detect git hook installation status
This commit is contained in:
parent
423fb66175
commit
10be919b0a
10
bin/penchant
10
bin/penchant
@ -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
|
||||
|
||||
|
@ -28,3 +28,29 @@ Feature: CLI
|
||||
"""
|
||||
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"
|
||||
|
@ -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
|
@ -0,0 +1,3 @@
|
||||
Then /^the output should not include "(.*?)"$/ do |text|
|
||||
@output.should_not include(text)
|
||||
end
|
@ -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
21
lib/penchant/hooks.rb
Normal 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
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
msg=$(cat $1)
|
||||
|
||||
OLD_GIT_DIR=$GIT_DIR
|
||||
|
||||
if [[ "${msg}" != *"[ci skip]"* ]]; then
|
||||
if [ "$(penchant gemfile-env)" != "remote" ]; then
|
||||
penchant gemfile remote
|
||||
# wtf mac os x lion
|
||||
if [ ! -z "$MY_RUBY_HOME" ]; then
|
||||
PATH="$MY_RUBY_HOME/bin:$PATH"
|
||||
fi
|
||||
|
||||
bundle exec rake
|
||||
if [[ "${msg}" != *"[ci skip]"* ]]; then
|
||||
bundle exec rake --trace
|
||||
R=$?
|
||||
if [ $R -ne 0 ]; then exit $R; fi
|
||||
fi
|
||||
|
@ -1,4 +1,2 @@
|
||||
#!/bin/bash
|
||||
|
||||
penchant gemfile remote --switch-back
|
||||
|
||||
|
@ -1,4 +1,2 @@
|
||||
#!/bin/bash
|
||||
|
||||
# this has been moved to commit-msg
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user