Permalink
Browse files

Add test for validating git fetch.

  • Loading branch information...
1 parent d5a6d03 commit 72224b2d96a436862911d99658d9ada65480b7cd @relistan relistan committed Jan 14, 2014
Showing with 17 additions and 7 deletions.
  1. +7 −5 lib/capistrano/deploy_tags.rb
  2. +10 −2 spec/capistrano_deploy_tags_spec.rb
@@ -2,11 +2,9 @@ module Capistrano
module DeployTags
def pending_git_changes?
# Do we have any changes vs HEAD on deployment branch?
- out = `git fetch 2>&1`
- if $?.success?
- ! (`git diff #{branch} --shortstat`.strip.empty?)
- else
- raise CommandError.new("git fetch failed:\n" + out)
+ `git fetch #{remote}`.tap do |output|
+ return !(`git diff #{branch} --shortstat`.strip.empty?) if exec_success?
+ raise "'git fetch #{remote}' failed:\n #{output}"
end
end
@@ -18,6 +16,10 @@ def safe_run(*args)
raise "#{args.join(" ")} failed!" unless system(*args)
end
+ def exec_success?
+ $?.success?
+ end
+
def validate_git_vars
unless exists?(:branch) && exists?(:stage)
logger.log Capistrano::Logger::IMPORTANT, 'Capistrano Deploytags requires that :branch and :stage be defined.'
@@ -24,13 +24,21 @@ def with_clean_repo(&block)
end
context "prepare_tree" do
- it "raises an error when not in a git tree" do
- FileUtils.chdir '/tmp'
+ before :each do
configuration.set(:branch, 'master')
configuration.set(:stage, 'test')
+ end
+
+ it "raises an error when not in a git tree" do
+ FileUtils.chdir '/tmp'
expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error('git checkout master failed!')
end
+ it "raises when unable to fetch" do
+ configuration.cdt.should_receive(:exec_success?).and_return(false)
+ expect { configuration.find_and_execute_task('git:prepare_tree') }.to raise_error(/'git fetch origin' failed/)
+ end
+
context "with a clean git tree" do
before :each do
configuration.set(:branch, 'master')

0 comments on commit 72224b2

Please sign in to comment.