Class: Lolcommits::InstallationMercurial
- Inherits:
-
Object
- Object
- Lolcommits::InstallationMercurial
- Defined in:
- lib/lolcommits/backends/installation_mercurial.rb
Overview
Methods to handle enabling and disabling of lolcommits
Constant Summary collapse
- HOOK_SECTION =
'hooks'
- HOOK_OPERATIONS =
%w(commit record crecord).freeze
Class Method Summary collapse
-
.do_disable ⇒ Object
IF –DISABLE, DO DISABLE.
-
.do_enable(capture_args = '') ⇒ Object
IF –ENABLE, DO ENABLE.
- .hook_script(capture_args = '') ⇒ Object
-
.lolcommits_hook_exists? ⇒ Boolean
does a mercurial hook exist with lolcommits commands?.
- .remove_existing_hook! ⇒ Object
- .repository ⇒ Object
-
.valid_hgrc? ⇒ Boolean
can we load the hgrc?.
Class Method Details
.do_disable ⇒ Object
IF –DISABLE, DO DISABLE
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 30 def self.do_disable config = repository.config if lolcommits_hook_exists? remove_existing_hook! info "uninstalled lolcommits hook (from #{config.path})" elsif config.exists? info "couldn't find an lolcommits hook (at #{config.path})" else info "no post commit hook found (at #{config.path}), so there is nothing to uninstall" end end |
.do_enable(capture_args = '') ⇒ Object
IF –ENABLE, DO ENABLE
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 14 def self.do_enable(capture_args = '') if lolcommits_hook_exists? # clear away any existing lolcommits hook remove_existing_hook! end config = repository.config HOOK_OPERATIONS.each do |op| config.add_setting(HOOK_SECTION, "post-#{op}.lolcommits", hook_script(capture_args)) end config.path end |
.hook_script(capture_args = '') ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 42 def self.hook_script(capture_args = '') ruby_path = Lolcommits::Platform.command_which('ruby', only_path: true) imagick_path = Lolcommits::Platform.command_which('identify', only_path: true) capture_cmd = "if [ \"$LOLCOMMITS_CAPTURE_DISABLED\" != \"true\" ]; then lolcommits --capture #{capture_args}; fi" exports = "LANG=\"#{ENV.fetch('LANG', nil)}\" && PATH=\"$PATH:#{ruby_path}:#{imagick_path}\"" if Lolcommits::Platform.platform_windows? exports = "set path=\"%PATH%;#{ruby_path};#{imagick_path}\"" end "#{exports} && #{capture_cmd}" end |
.lolcommits_hook_exists? ⇒ Boolean
does a mercurial hook exist with lolcommits commands?
60 61 62 63 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 60 def self.lolcommits_hook_exists? config = repository.config config.exists? && config.setting_exists?(HOOK_SECTION, 'post-crecord.lolcommits') end |
.remove_existing_hook! ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 70 def self.remove_existing_hook! config = repository.config HOOK_OPERATIONS.each do |op| setting = "post-#{op}.lolcommits" if config.setting_exists?(HOOK_SECTION, setting) config.delete_setting!(HOOK_SECTION, setting) end end end |
.repository ⇒ Object
55 56 57 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 55 def self.repository Mercurial::Repository.open('.') end |
.valid_hgrc? ⇒ Boolean
can we load the hgrc?
66 67 68 |
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 66 def self.valid_hgrc? repository.config.exists? end |