ensure git hooks not installed if no git repo found

This commit is contained in:
John Bintz 2012-07-23 10:25:42 -04:00
parent 6679a65cdf
commit 64d4b5a323
4 changed files with 29 additions and 10 deletions

View File

@ -9,25 +9,32 @@ class PenchantCLI < Thor
include Thor::Actions include Thor::Actions
source_root File.expand_path('../..', __FILE__) source_root File.expand_path('../..', __FILE__)
SCRIPT_DIR = 'script'
CLONE_DIR = '..'
desc "install", "Copy the common scripts to the project" desc "install", "Copy the common scripts to the project"
method_options :dir => 'script' method_options :dir => SCRIPT_DIR
def install def install
directory 'template/script', options[:dir] directory 'template/script', options[:dir]
Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) } Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) }
Dir['script/hooks/*'].each do |hook| if File.directory?('.git')
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/#{File.split(hook).last}"
end
else
puts "No git repository detected here. Skipping git hook installation..."
end end
end end
desc "update", "Update the installed scripts" desc "update", "Update the installed scripts"
method_options :dir => 'script' method_options :dir => SCRIPT_DIR
def update def update
install install
end end
desc "convert", "Make an existing project Penchant-isized" desc "convert", "Make an existing project Penchant-isized"
method_options :dir => 'script' method_options :dir => SCRIPT_DIR
def convert def convert
install install
FileUtils.mv 'Gemfile', 'Gemfile.penchant' FileUtils.mv 'Gemfile', 'Gemfile.penchant'
@ -63,10 +70,10 @@ class PenchantCLI < Thor
puts get_current_env puts get_current_env
end end
desc "bootstrap [DIR = ..]", "Download all referred-to git repos to the specified directory" desc "bootstrap [DIR = #{CLONE_DIR}]", "Download all referred-to git repos to the specified directory"
def bootstrap(dir = '..') def bootstrap(dir = CLONE_DIR)
Penchant::Gemfile.defined_git_repos.each do |repo| Penchant::Gemfile.defined_git_repos.each do |repo|
puts "Cloning #{repo} to #{dir}." puts "Cloning #{repo} to #{dir}"
repo.clone_to(dir) repo.clone_to(dir)
end end
end end

View File

@ -16,3 +16,15 @@ Feature: CLI
""" """
And the output should include "fallback: other" 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"

View File

@ -2,7 +2,7 @@ require 'fakefs/safe'
require 'penchant' require 'penchant'
require 'mocha' require 'mocha'
World(Mocha::Standalone) World(Mocha::API)
Before('@fakefs') do Before('@fakefs') do
FakeFS.activate! FakeFS.activate!

View File

@ -1,3 +1,3 @@
module Penchant module Penchant
VERSION = "0.2.11" VERSION = "0.2.12"
end end