module GGSM::Hooks

Public Instance Methods

check_hooks() click to toggle source
# File lib/ggsm/hook/hooks.rb, line 3
def check_hooks
  if update_hooks
    install_billow
    subs = get_submodule
    subs.each do |sub|
      cp_hooks(sub)
    end
  end
end
cp_files(target_path) click to toggle source
# File lib/ggsm/hook/hooks.rb, line 46
def cp_files(target_path)
  path = `gem which ggsm`.split('/ggsm.rb')[0]
  `cp #{path}/ggsm/hook/commit-msg #{target_path}/commit-msg`
  `cp #{path}/ggsm/hook/pre-commit  #{target_path}/pre-commit`
end
cp_hooks(sub) click to toggle source
# File lib/ggsm/hook/hooks.rb, line 41
def cp_hooks(sub)
  target_path = ".git/modules/#{sub}/hooks"
  cp_files(target_path)
end
install_billow() click to toggle source
# File lib/ggsm/hook/hooks.rb, line 13
def install_billow
  path = `gem which ggsm`.split('/ggsm.rb')[0]
  `sudo sh #{path}/res/install_billow.sh`
end
update_hooks() click to toggle source
# File lib/ggsm/hook/hooks.rb, line 18
def update_hooks
  version = `ggsm v`
  ggsm_path = '.git/ggsm'
  unless File.exist?(ggsm_path)
    Dir.mkdir(ggsm_path)
  end

  config_path = "#{ggsm_path}/VERSION"
  target_path = '.git/hooks'

  if !File.exist?(config_path) || version != IO.read(config_path)
    cp_files(target_path)

    file = File.new(config_path, 'w')
    file << version
    file.close

    puts '已更新Hooks'.blue
    return true
  end
  false
end