Sha256: 966410bcff1b87975a16b03342c24ffa18ed57a9767d10e82cf46b138350bf63

Contents?: true

Size: 789 Bytes

Versions: 2

Compression:

Stored size: 789 Bytes

Contents

require 'pathname'

module Penchant
  class Hooks
    HOOKS_DIR = 'script/hooks'
    GIT_HOOKS_DIR = '.git/hooks'

    def self.installed?
      if File.directory?(HOOKS_DIR)
        Dir[File.join(HOOKS_DIR, '*')].each do |file|
          target = File.join(GIT_HOOKS_DIR, File.basename(file))
          return false if !File.symlink?(target)
          return false if !File.expand_path(File.readlink(target)) == File.expand_path(file)
        end

        true
      else
        # no script/hooks dir, so we must not want them
        true
      end
    end

    def self.install!
      puts "[penchant] installing git hooks"

      Dir['script/hooks/*'].each do |hook|
        FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
penchant-0.2.16 lib/penchant/hooks.rb
penchant-0.2.15 lib/penchant/hooks.rb