Sha256: 846837e45111e36ba49ffd453fc455bd6983926e68ddb0efceaafa50024319f9

Contents?: true

Size: 1020 Bytes

Versions: 16

Compression:

Stored size: 1020 Bytes

Contents

module GGSM
  module Hooks
    def check_hooks
      if update_hooks
        subs = get_submodule
        subs.each do |sub|
          cp_hooks(sub)
        end
      end
    end

    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

    def cp_hooks(sub)
      target_path = ".git/modules/#{sub}/hooks"
      cp_files(target_path)
    end

    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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ggsm-1.8.6 lib/ggsm/hook/hooks.rb
ggsm-1.8.5 lib/ggsm/hook/hooks.rb
ggsm-1.8.4 lib/ggsm/hook/hooks.rb
ggsm-1.8.3 lib/ggsm/hook/hooks.rb
ggsm-1.8.2 lib/ggsm/hook/hooks.rb
ggsm-1.8.1 lib/ggsm/hook/hooks.rb
ggsm-1.8.0 lib/ggsm/hook/hooks.rb
ggsm-1.7.6 lib/ggsm/util/hooks.rb
ggsm-1.7.5 lib/ggsm/util/hooks.rb
ggsm-1.7.3 lib/ggsm/util/hooks.rb
ggsm-1.7.2 lib/ggsm/util/hooks.rb
ggsm-1.7.1 lib/ggsm/util/hooks.rb
ggsm-1.7.0 lib/ggsm/util/hooks.rb
ggsm-1.6.2 lib/ggsm/util/hooks.rb
ggsm-1.6.1 lib/ggsm/util/hooks.rb
ggsm-1.6.0 lib/ggsm/util/hooks.rb