diff --git a/bin/penchant b/bin/penchant index 6178092..de3e4c7 100755 --- a/bin/penchant +++ b/bin/penchant @@ -14,7 +14,10 @@ class PenchantCLI < Thor def install directory 'template/script', options[:dir] Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) } - FileUtils.ln_sf File.join(Dir.pwd, 'script/hooks/pre-commit'), '.git/hooks/pre-commit' + + Dir['script/hooks/*'].each do |hook| + FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}" + end end desc "convert", "Make an existing project Penchant-isized" @@ -49,7 +52,9 @@ class PenchantCLI < Thor no_tasks do def get_current_env gemfile = Penchant::Gemfile.new - gemfile.environment + out = [ gemfile.environment ] + out << "deployment" if gemfile.deployment? + out.join(' ') end end diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 7a347fd..ce4e574 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -42,7 +42,11 @@ module Penchant end def environment - File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1] + File.readlines(gemfile_path).first.strip[%r{environment: ([^, ]*)}, 1] + end + + def deployment? + File.readlines(gemfile_path).first['deployment mode'] != nil end def switch_to!(gemfile_env = nil, deployment = false) diff --git a/spec/lib/penchant/gemfile_spec.rb b/spec/lib/penchant/gemfile_spec.rb index bdacc92..e743c99 100644 --- a/spec/lib/penchant/gemfile_spec.rb +++ b/spec/lib/penchant/gemfile_spec.rb @@ -47,6 +47,17 @@ describe Penchant::Gemfile do GEMFILE its(:environment) { should == environment } + it { should_not be_deployment } + end + + context 'deployment' do + let(:environment) { 'test' } + let(:data) { <<-GEMFILE } +# generated by penchant, environment: #{environment}, deployment mode +GEMFILE + + its(:environment) { should == environment } + it { should be_deployment } end end diff --git a/template/script/hooks/post-commit b/template/script/hooks/post-commit new file mode 100755 index 0000000..2231ee1 --- /dev/null +++ b/template/script/hooks/post-commit @@ -0,0 +1,4 @@ +#!/bin/bash + +penchant gemfile remote + diff --git a/template/script/hooks/pre-commit b/template/script/hooks/pre-commit index 42c60b3..fc9f07f 100755 --- a/template/script/hooks/pre-commit +++ b/template/script/hooks/pre-commit @@ -2,7 +2,7 @@ OLD_GIT_DIR=$GIT_DIR -if [ "$(penchant gemfile-env)" != "remote" ]; then +if [ "$(penchant gemfile-env)" != "remote deployment" ]; then unset GIT_DIR penchant gemfile remote --deployment GIT_DIR=$OLD_GIT_DIR