detect git hook installation status

This commit is contained in:
John Bintz 2012-07-24 10:48:11 -04:00
parent 423fb66175
commit 10be919b0a
9 changed files with 71 additions and 11 deletions

View File

@ -45,6 +45,8 @@ class PenchantCLI < Thor
method_options :switch_back => false
desc "gemfile ENV", "Switch the gemfile environment, or rebuild the current environment if not given"
def gemfile(env = get_current_env)
check_git_hooks!
if env
if options[:switch_back]
puts "[penchant] Switching back, fallback: #{env}..."
@ -93,9 +95,17 @@ class PenchantCLI < Thor
out << "deployment" if gemfile.deployment?
out.join(' ')
end
def check_git_hooks!
if !Penchant::Hooks.installed?
puts "[penchant] git hooks not installed. Run script/install-git-hooks."
puts
end
end
end
default_task :gemfile
end
PenchantCLI.start

View File

@ -27,4 +27,30 @@ Feature: CLI
source :rubygems
"""
And the output should include "No git"
@wip
Scenario: Run in a project where the git hooks are not set up
Given I have the file "tmp/Gemfile.penchant" with the content:
"""
gem 'rake'
"""
Given I have the file "tmp/script/hooks/pre-commit" with the content:
"""
a penchant hook
"""
When I run "bin/penchant gemfile remote" in the "tmp" directory
Then the output should include "git hooks not installed"
@wip
Scenario: Run in a project where git hooks are set up
Given I have the file "tmp/Gemfile.penchant" with the content:
"""
gem 'rake'
"""
Given I have the file "tmp/script/hooks/pre-commit" with the content:
"""
a penchant hook
"""
Given I have the symlink "tmp/.git/hooks/pre-commit" which points to "tmp/script/hooks/pre-commit"
When I run "bin/penchant gemfile remote" in the "tmp" directory
Then the output should not include "git hooks not installed"

View File

@ -0,0 +1,4 @@
Given /^I have the symlink "(.*?)" which points to "(.*?)"$/ do |source, target|
FileUtils.mkdir_p(File.dirname(source))
File.symlink(target, source)
end

View File

@ -0,0 +1,3 @@
Then /^the output should not include "(.*?)"$/ do |text|
@output.should_not include(text)
end

View File

@ -2,4 +2,5 @@ module Penchant
autoload :Gemfile, 'penchant/gemfile'
autoload :Repo, 'penchant/repo'
autoload :DotPenchant, 'penchant/dot_penchant'
autoload :Hooks, 'penchant/hooks'
end

21
lib/penchant/hooks.rb Normal file
View File

@ -0,0 +1,21 @@
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
end
end
end
end

View File

@ -2,14 +2,13 @@
msg=$(cat $1)
OLD_GIT_DIR=$GIT_DIR
# wtf mac os x lion
if [ ! -z "$MY_RUBY_HOME" ]; then
PATH="$MY_RUBY_HOME/bin:$PATH"
fi
if [[ "${msg}" != *"[ci skip]"* ]]; then
if [ "$(penchant gemfile-env)" != "remote" ]; then
penchant gemfile remote
fi
bundle exec rake
bundle exec rake --trace
R=$?
if [ $R -ne 0 ]; then exit $R; fi
fi

View File

@ -1,4 +1,2 @@
#!/bin/bash
penchant gemfile remote --switch-back

View File

@ -1,4 +1,2 @@
#!/bin/bash
# this has been moved to commit-msg