diff --git a/bin/penchant b/bin/penchant index 21b06e5..d6708d4 100755 --- a/bin/penchant +++ b/bin/penchant @@ -23,6 +23,16 @@ class PenchantCLI < Thor else puts "No git repository detected here. Skipping git hook installation..." end + + if !File.file?('Gemfile') && !File.file?('Gemfile.penchant') + FileUtils.touch('Gemfile.penchant') + + prepend_to_file 'Gemfile.penchant', <<-RB +source :rubygems + RB + + install_gemfile_penchant + end end desc "update", "Update the installed scripts" @@ -36,18 +46,7 @@ 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) + install_gemfile_penchant end method_options :deployment => false @@ -118,6 +117,20 @@ property :github, :git => 'git://github.com/$1/%s.git' puts end end + + def install_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 end default_task :gemfile diff --git a/features/cli.feature b/features/cli.feature index 9f3604d..7e4dbe4 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -61,3 +61,18 @@ Feature: CLI 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" + + @wip + Scenario: Install Penchant into a directory with no Gemfile + Given I have the directory "tmp" + When I run "bin/penchant install" in the "tmp" directory + Then the file "tmp/Gemfile.penchant" should include the following content: + """ + source :rubygems + """ + Then the file "tmp/Gemfile" should include the following content: + """ + source :rubygems + """ + And the output should include "No git" + diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index 039b934..8ecc4f5 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.18" + VERSION = "0.2.19" end