Class: Lolcommits::Installation
- Inherits:
-
Object
- Object
- Lolcommits::Installation
- Defined in:
- lib/lolcommits/installation.rb
Overview
Methods to handle enabling and disabling of lolcommits
Constant Summary collapse
- HOOK_PATH =
File.join '.git', 'hooks', 'post-commit'
- HOOK_DIR =
File.join '.git', 'hooks'
Class Method Summary collapse
-
.do_disable ⇒ Object
IF –DISABLE, DO DISABLE.
-
.do_enable ⇒ Object
IF –ENABLE, DO ENABLE.
Class Method Details
.do_disable ⇒ Object
IF –DISABLE, DO DISABLE
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lolcommits/installation.rb', line 51 def self.do_disable if lolcommits_hook_exists? remove_existing_hook! info "uninstalled lolcommits hook (from #{HOOK_PATH})" elsif File.exists?(HOOK_PATH) info "couldn't find an lolcommits hook (at #{HOOK_PATH})" if File.read(HOOK_PATH) =~ /lolcommit/ info "warning: an older-style lolcommit hook may still exist, edit #{HOOK_PATH} to remove it manually" end else info "no post commit hook found (at #{HOOK_PATH}), so there is nothing to uninstall" end end |
.do_enable ⇒ Object
IF –ENABLE, DO ENABLE
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lolcommits/installation.rb', line 13 def self.do_enable if not File.directory?('.git') fatal "You don't appear to be in the base directory of a git project." exit 1 end # its possible a hooks dir doesnt exist, so create it if so if not File.directory?(HOOK_DIR) Dir.mkdir(HOOK_DIR) end # clear away any existing lolcommits hook if hook_file_exists? remove_existing_hook! if lolcommits_hook_exists? # check for a good shebang line in the existing hook unless good_shebang? warn "the existing hook (at #{HOOK_PATH}) doesn't start with with a good shebang; like #!/bin/sh" exit 1 end end File.open(HOOK_PATH, hook_file_exists? ? 'a' : 'w') do |f| f.write(hook_script(!hook_file_exists?)) end FileUtils.chmod 0755, HOOK_PATH info 'installed lolcommit hook to:' info " -> #{File.expand_path(HOOK_PATH)}" info '(to remove later, you can use: lolcommits --disable)' # we dont symlink, but rather install a small stub that calls the one from path # that way, as gem version changes, script updates even if new file thus breaking symlink end |