From 72224b2d96a436862911d99658d9ada65480b7cd Mon Sep 17 00:00:00 2001 From: Karl Matthias Date: Mon, 13 Jan 2014 20:57:13 -0800 Subject: [PATCH] Add test for validating git fetch. --- lib/capistrano/deploy_tags.rb | 12 +++++++----- spec/capistrano_deploy_tags_spec.rb | 12 ++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/capistrano/deploy_tags.rb b/lib/capistrano/deploy_tags.rb index 1a49fa2..515fdc4 100644 --- a/lib/capistrano/deploy_tags.rb +++ b/lib/capistrano/deploy_tags.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 @@ module Capistrano 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.' diff --git a/spec/capistrano_deploy_tags_spec.rb b/spec/capistrano_deploy_tags_spec.rb index a94276f..2a4b3fd 100644 --- a/spec/capistrano_deploy_tags_spec.rb +++ b/spec/capistrano_deploy_tags_spec.rb @@ -24,13 +24,21 @@ describe Capistrano::DeployTags do 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')