diff --git a/README.md b/README.md index 538294b..c136a70 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ Yeah, it's a `Gemfile` with some extras: # Gemfile.penchant source :rubygems +# ensure git hooks are installed when a gemfile is processed, see below +ensure_git_hooks! + gem 'rails', '3.2.3' # expands to: # @@ -173,6 +176,13 @@ It runs `penchant gemfile remote` then runs `bundle exec rake`. Make sure your d tests and performs any other magic necessary before each commit. Your re-environmented Gemfile and Gemfile.lock will be added to your commit if they've changed. +### Ensuring git hooks get installed + +I find that when I pull down new projects I never remember to install the git hooks, which involves an awkward running +of `bundle exec rake` *after* I've already committed code. Since we have computers now, and they can be told to do things, +you can add `ensure_git_hooks!` anywhere in your `Gemfile.penchant` to make sure the git hooks are symlinked to the ones +in the `script/hooks` directory with every processing of `Gemfile.penchant`. + ### Skipping all that Rake falderal? Do it Travis CI style: stick `[ci skip]` in your commit message. That's why the meat of the git hooks resides in diff --git a/bin/penchant b/bin/penchant index e9ae180..6310ab3 100755 --- a/bin/penchant +++ b/bin/penchant @@ -19,9 +19,7 @@ class PenchantCLI < Thor Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) } if File.directory?('.git') - Dir['script/hooks/*'].each do |hook| - FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}" - end + Penchant::Hooks.install! else puts "No git repository detected here. Skipping git hook installation..." end diff --git a/features/cli.feature b/features/cli.feature index 3ece4c7..3261860 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -28,7 +28,6 @@ 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: """ @@ -41,7 +40,6 @@ Feature: CLI 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: """ diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index 5621bef..b67b407 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -278,3 +278,19 @@ Feature: Gemfiles gem "one", {:git=>"git://github.com/john/one.git"} """ + @mocha + Scenario: Force installing of git hooks if the gemfile asks for it + Given I expect git hooks to be installed + Given I have the file "Gemfile.penchant" with the content: + """ + ensure_git_hooks! + + gem 'one' + """ + When I rebuild the Gemfile for "local" mode + Then the file "Gemfile" should have the following content: + """ + # generated by penchant, environment: local + gem "one" + """ + diff --git a/features/step_definitions/given/i_expect_git_hooks_to_be_installed.rb b/features/step_definitions/given/i_expect_git_hooks_to_be_installed.rb new file mode 100644 index 0000000..1f3c0f9 --- /dev/null +++ b/features/step_definitions/given/i_expect_git_hooks_to_be_installed.rb @@ -0,0 +1,3 @@ +Given /^I expect git hooks to be installed$/ do + Penchant::Hooks.expects(:install!) +end diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 9a45b53..92fb806 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -163,6 +163,10 @@ module Penchant yield if !is_deployment end + def ensure_git_hooks! + Penchant::Hooks.install! + end + def os(*args) yield if args.include?(current_os) end diff --git a/lib/penchant/hooks.rb b/lib/penchant/hooks.rb index f6a2607..54daf22 100644 --- a/lib/penchant/hooks.rb +++ b/lib/penchant/hooks.rb @@ -16,6 +16,14 @@ module Penchant true end end + + def self.install! + puts "[penchant] installing git hooks" + + Dir['script/hooks/*'].each do |hook| + FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}" + end + end end end diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index da58f0a..31ea7d9 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.13" + VERSION = "0.2.14" end