From e84f6a359d1391eea3b21d09a224c5b25c3fc8e2 Mon Sep 17 00:00:00 2001 From: Barrie Bremner Date: Wed, 30 Jan 2013 13:48:00 +0000 Subject: [PATCH] Check state of local tree with git status, rather than a diff, since there's no guarantee we're at the right point on the branch at this stage. --- lib/capistrano/deploy_tags.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/capistrano/deploy_tags.rb b/lib/capistrano/deploy_tags.rb index cad3a23..2d251e7 100644 --- a/lib/capistrano/deploy_tags.rb +++ b/lib/capistrano/deploy_tags.rb @@ -1,8 +1,9 @@ module Capistrano module DeployTags - def pending_git_changes? - # Do we have any changes vs HEAD on deployment branch? - !(`git fetch && git diff #{branch} --shortstat`.strip.empty?) + + def uncommitted_git_changes? + # Is the working directory clean? + !( `git status --porcelain`.strip.empty? ) end def git_tag_for(stage) @@ -40,13 +41,12 @@ module Capistrano task :prepare_tree, :except => { :no_release => true } do cdt.validate_git_vars - logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy HEAD from branch '#{branch}' to '#{stage}'" - - if cdt.pending_git_changes? - logger.log Capistrano::Logger::IMPORTANT, "Whoa there, partner. Dirty trees can't deploy. Git yerself clean first." - raise 'Dirty git tree' + if cdt.uncommitted_git_changes? + logger.log Capistrano::Logger::IMPORTANT, "Sorry, you have uncommitted changes. Please commit or stash them." end + logger.log Capistrano::Logger::IMPORTANT, "Preparing to deploy HEAD from branch '#{branch}' to '#{stage}'" + cdt.safe_run "git", "checkout", branch cdt.safe_run "git", "pull", "origin", branch if cdt.has_remote? end