From 64d4b5a3230487e57b7882cc3b2fc34da25bf6a6 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 23 Jul 2012 10:25:42 -0400 Subject: [PATCH] ensure git hooks not installed if no git repo found --- bin/penchant | 23 +++++++++++++++-------- features/cli.feature | 12 ++++++++++++ features/support/env.rb | 2 +- lib/penchant/version.rb | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/bin/penchant b/bin/penchant index 6312df4..96c2135 100755 --- a/bin/penchant +++ b/bin/penchant @@ -9,25 +9,32 @@ class PenchantCLI < Thor include Thor::Actions source_root File.expand_path('../..', __FILE__) + SCRIPT_DIR = 'script' + CLONE_DIR = '..' + desc "install", "Copy the common scripts to the project" - method_options :dir => 'script' + method_options :dir => SCRIPT_DIR def install directory 'template/script', options[:dir] Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) } - Dir['script/hooks/*'].each do |hook| - FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}" + 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 + else + puts "No git repository detected here. Skipping git hook installation..." end end desc "update", "Update the installed scripts" - method_options :dir => 'script' + method_options :dir => SCRIPT_DIR def update install end desc "convert", "Make an existing project Penchant-isized" - method_options :dir => 'script' + method_options :dir => SCRIPT_DIR def convert install FileUtils.mv 'Gemfile', 'Gemfile.penchant' @@ -63,10 +70,10 @@ class PenchantCLI < Thor puts get_current_env end - desc "bootstrap [DIR = ..]", "Download all referred-to git repos to the specified directory" - def bootstrap(dir = '..') + desc "bootstrap [DIR = #{CLONE_DIR}]", "Download all referred-to git repos to the specified directory" + def bootstrap(dir = CLONE_DIR) Penchant::Gemfile.defined_git_repos.each do |repo| - puts "Cloning #{repo} to #{dir}." + puts "Cloning #{repo} to #{dir}" repo.clone_to(dir) end end diff --git a/features/cli.feature b/features/cli.feature index 16fbbb6..2204dc2 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -16,3 +16,15 @@ Feature: CLI """ And the output should include "fallback: other" + Scenario: Try to convert a project, ignoring git hooks + Given I have the file "tmp/Gemfile" with the content: + """ + source :rubygems + """ + When I run "bin/penchant convert" in the "tmp" directory + Then the file "tmp/Gemfile.penchant" should have the following content: + """ + source :rubygems + """ + And the output should include "No git" + diff --git a/features/support/env.rb b/features/support/env.rb index 6f8f552..25e5b35 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -2,7 +2,7 @@ require 'fakefs/safe' require 'penchant' require 'mocha' -World(Mocha::Standalone) +World(Mocha::API) Before('@fakefs') do FakeFS.activate! diff --git a/lib/penchant/version.rb b/lib/penchant/version.rb index f755ab7..fad59b2 100644 --- a/lib/penchant/version.rb +++ b/lib/penchant/version.rb @@ -1,3 +1,3 @@ module Penchant - VERSION = "0.2.11" + VERSION = "0.2.12" end