From 384039b174e93f14111cd5bd8a3ab68a3774e284 Mon Sep 17 00:00:00 2001 From: "sbc@chromium.org" Date: Mon, 13 Oct 2014 21:01:00 +0000 Subject: [PATCH] Improve error handling in git-rebase-update Don't discard stderr from failed rebase operations I had an issue where stdout of the failed rebase was empty but stderr contained: First, rewinding head to replay your work on top of it... Dirty index: cannot apply patches (dirty: internal_gyp third_party/html_office). Also, in my case the second rebase was actually succeeding for some reason, which is clearly no expected, so assert in this case. BUG=410339 Review URL: https://codereview.chromium.org/645763002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@292444 0039d316-1c4b-4281-b951-d872f2087c98 --- git_common.py | 6 +++--- git_rebase_update.py | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/git_common.py b/git_common.py index 99ed53cc4..7f2e13b62 100644 --- a/git_common.py +++ b/git_common.py @@ -497,7 +497,7 @@ def parse_commitrefs(*commitrefs): raise BadCommitRefException(commitrefs) -RebaseRet = collections.namedtuple('RebaseRet', 'success message') +RebaseRet = collections.namedtuple('RebaseRet', 'success stdout stderr') def rebase(parent, start, branch, abort=False): @@ -521,11 +521,11 @@ def rebase(parent, start, branch, abort=False): if TEST_MODE: args.insert(0, '--committer-date-is-author-date') run('rebase', *args) - return RebaseRet(True, '') + return RebaseRet(True, '', '') except subprocess2.CalledProcessError as cpe: if abort: run('rebase', '--abort') - return RebaseRet(False, cpe.stdout) + return RebaseRet(False, cpe.stdout, cpe.stderr) def remove_merge_base(branch): diff --git a/git_rebase_update.py b/git_rebase_update.py index aa69fe1fd..53e0287dd 100755 --- a/git_rebase_update.py +++ b/git_rebase_update.py @@ -130,7 +130,8 @@ def rebase_branch(branch, parent, start_hash): if git.hash_one(parent) != start_hash: # Try a plain rebase first print 'Rebasing:', branch - if not git.rebase(parent, start_hash, branch, abort=True).success: + rebase_ret = git.rebase(parent, start_hash, branch, abort=True) + if not rebase_ret.success: # TODO(iannucci): Find collapsible branches in a smarter way? print "Failed! Attempting to squash", branch, "...", squash_branch = branch+"_squash_attempt" @@ -148,14 +149,19 @@ def rebase_branch(branch, parent, start_hash): git.rebase(parent, start_hash, branch) else: # rebase and leave in mid-rebase state. - git.rebase(parent, start_hash, branch) + # This second rebase attempt should always fail in the same + # way that the first one does. If it magically succeeds then + # something very strange has happened. + second_rebase_ret = git.rebase(parent, start_hash, branch) + assert(not second_rebase_ret.success) print "Failed!" print - print "Here's what git-rebase had to say:" - print squash_ret.message + print "Here's what git-rebase (squashed) had to say:" print + print squash_ret.stdout + print squash_ret.stderr print textwrap.dedent( - """ + """\ Squashing failed. You probably have a real merge conflict. Your working copy is in mid-rebase. Either: