Class: Lolcommits::InstallationMercurial

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/backends/installation_mercurial.rb

Overview

Methods to handle enabling and disabling of lolcommits

Constant Summary collapse

HOOK_SECTION =
'hooks'.freeze
HOOK_OPERATIONS =
%w(commit record crecord).freeze

Class Method Summary collapse

Class Method Details

.do_disableObject

IF –DISABLE, DO DISABLE



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 28

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



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 12

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



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 40

def self.hook_script(capture_args = '')
  ruby_path     = Lolcommits::Platform.command_which('ruby', true)
  imagick_path  = Lolcommits::Platform.command_which('identify', true)
  capture_cmd   = "if [ \"$LOLCOMMITS_CAPTURE_DISABLED\" != \"true\" ]; then lolcommits --capture #{capture_args}; fi"
  exports       = "LANG=\"#{ENV['LANG']}\" && PATH=\"#{ruby_path}:#{imagick_path}:$PATH\""

  if Lolcommits::Platform.platform_windows?
    exports = "set path=\"#{ruby_path};#{imagick_path};%PATH%\""
  end

  "#{exports} && #{capture_cmd}"
end

.lolcommits_hook_exists?Boolean

does a mercurial hook exist with lolcommits commands?

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 58

def self.lolcommits_hook_exists?
  config = repository.config
  config.exists? && config.setting_exists?(HOOK_SECTION, 'post-crecord.lolcommits')
end

.remove_existing_hook!Object



68
69
70
71
72
73
74
75
76
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 68

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

.repositoryObject



53
54
55
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 53

def self.repository
  Mercurial::Repository.open('.')
end

.valid_hgrc?Boolean

can we load the hgrc?

Returns:

  • (Boolean)


64
65
66
# File 'lib/lolcommits/backends/installation_mercurial.rb', line 64

def self.valid_hgrc?
  repository.config.exists?
end