diff --git a/README.md b/README.md index c136a70..1e313dd 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,12 @@ It then runs `bundle install`. You can also run `penchant gemfile ENV`. Just straight `penchant gemfile` will rebuild the `Gemfile` from `Gemfile.penchant` for whatever environment the `Gemfile` is currently using. +If you have an existing project, `penchant convert` will convert the `Gemfile` into a `Gemfile.penchant` +and add some bonuses, like defining that anything in `env :local` blocks automatically reference `..`, +ensuring that hooks are always installed when `penchant gemfile` is executed, and adding the `:github` gem property +that lets you pass in the username of the repo to reference that repo: +`gem 'penchant', :github => 'johnbintz'`. + ### Deployment mode Use `no_deployment` blocks to indicate gems that shouldn't even appear in `Gemfiles` destined for diff --git a/bin/penchant b/bin/penchant index 9269fe7..21b06e5 100755 --- a/bin/penchant +++ b/bin/penchant @@ -36,6 +36,17 @@ class PenchantCLI < Thor def convert install FileUtils.mv 'Gemfile', 'Gemfile.penchant' + prepend_to_file 'Gemfile.penchant', <<-RB +# ensure git hooks are always installed +ensure_git_hooks! + +# everything in the :local env is assumed to be a sibling directory of this one +defaults_for env(:local), :path => '../%s' + +# reference a github repository with gem 'my-gem', :github => 'username' +property :github, :git => 'git://github.com/$1/%s.git' + + RB gemfile(:remote) end diff --git a/features/cli.feature b/features/cli.feature index d781555..9f3604d 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -22,7 +22,7 @@ Feature: CLI source :rubygems """ When I run "bin/penchant convert" in the "tmp" directory - Then the file "tmp/Gemfile.penchant" should have the following content: + Then the file "tmp/Gemfile.penchant" should include the following content: """ source :rubygems """ diff --git a/features/step_definitions/then/the_file_tmp_gemfile_penchant_should_include_the_following_content.rb b/features/step_definitions/then/the_file_tmp_gemfile_penchant_should_include_the_following_content.rb new file mode 100644 index 0000000..fea4a11 --- /dev/null +++ b/features/step_definitions/then/the_file_tmp_gemfile_penchant_should_include_the_following_content.rb @@ -0,0 +1,3 @@ +Then /^the file "(.*?)" should include the following content:$/ do |file, string| + File.read(file).should include(string) +end diff --git a/lib/penchant/hooks.rb b/lib/penchant/hooks.rb index 8ccb68e..9b795b5 100644 --- a/lib/penchant/hooks.rb +++ b/lib/penchant/hooks.rb @@ -21,12 +21,18 @@ module Penchant end def self.install! - puts "[penchant] installing git hooks" + if git? + 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}" + Dir['script/hooks/*'].each do |hook| + FileUtils.ln_sf File.join(Dir.pwd, hook), "#{GIT_HOOKS_DIR}/#{File.split(hook).last}" + end end end + + def self.git? + File.directory?(GIT_HOOKS_DIR) + end end end diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index b062dc1..83b93ea 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.16" + VERSION = "0.2.17" end