Module: DNGG::Hooks
- Included in:
- Submodule
- Defined in:
- lib/dngg/hook/hooks.rb
Instance Method Summary collapse
- #check_hooks ⇒ Object
- #cp_files(target_path) ⇒ Object
- #cp_hooks(sub) ⇒ Object
- #update_hooks ⇒ Object
Instance Method Details
#check_hooks ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/dngg/hook/hooks.rb', line 3 def check_hooks if update_hooks subs = get_submodule subs.each do |sub| cp_hooks(sub) end end end |
#cp_files(target_path) ⇒ Object
40 41 42 43 44 |
# File 'lib/dngg/hook/hooks.rb', line 40 def cp_files(target_path) path = `gem which dngg`.split('/dngg.rb')[0] `cp #{path}/dngg/hook/commit-msg #{target_path}/commit-msg` `cp #{path}/dngg/hook/pre-commit #{target_path}/pre-commit` end |
#cp_hooks(sub) ⇒ Object
35 36 37 38 |
# File 'lib/dngg/hook/hooks.rb', line 35 def cp_hooks(sub) target_path = ".git/modules/#{sub}/hooks" cp_files(target_path) end |
#update_hooks ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dngg/hook/hooks.rb', line 12 def update_hooks version = `dngg v` ggsm_path = '.git/dngg' 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 |