add post-commit script

This commit is contained in:
John Bintz 2011-10-13 14:27:02 -04:00
parent 25f9f7e3fb
commit 9354fed2dc
5 changed files with 28 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -0,0 +1,4 @@
#!/bin/bash
penchant gemfile remote

View File

@ -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