Add test for validating git fetch.

This commit is contained in:
Karl Matthias
2014-01-13 20:57:13 -08:00
parent d5a6d036c9
commit 72224b2d96
2 changed files with 17 additions and 7 deletions
+7 -5
View File
@@ -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.'
+10 -2
View File
@@ -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')