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

View File

@ -28,3 +28,29 @@ Feature: CLI
""" """
And the output should include "No git" 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 :Gemfile, 'penchant/gemfile'
autoload :Repo, 'penchant/repo' autoload :Repo, 'penchant/repo'
autoload :DotPenchant, 'penchant/dot_penchant' autoload :DotPenchant, 'penchant/dot_penchant'
autoload :Hooks, 'penchant/hooks'
end 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) 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 [[ "${msg}" != *"[ci skip]"* ]]; then
if [ "$(penchant gemfile-env)" != "remote" ]; then bundle exec rake --trace
penchant gemfile remote
fi
bundle exec rake
R=$? R=$?
if [ $R -ne 0 ]; then exit $R; fi if [ $R -ne 0 ]; then exit $R; fi
fi fi

View File

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

View File

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