Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: git_rebase_update.py

Issue 645763002: Improve error handling in git-rebase-update (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « git_common.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 Tool to update all branches to have the latest changes from their upstreams. 7 Tool to update all branches to have the latest changes from their upstreams.
8 """ 8 """
9 9
10 import argparse 10 import argparse
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 back_ups += 1 123 back_ups += 1
124 parent = git.run('rev-parse', parent+'~') 124 parent = git.run('rev-parse', parent+'~')
125 125
126 if back_ups: 126 if back_ups:
127 logging.debug('Backed parent up by %d from %s to %s', 127 logging.debug('Backed parent up by %d from %s to %s',
128 back_ups, orig_parent, parent) 128 back_ups, orig_parent, parent)
129 129
130 if git.hash_one(parent) != start_hash: 130 if git.hash_one(parent) != start_hash:
131 # Try a plain rebase first 131 # Try a plain rebase first
132 print 'Rebasing:', branch 132 print 'Rebasing:', branch
133 if not git.rebase(parent, start_hash, branch, abort=True).success: 133 rebase_ret = git.rebase(parent, start_hash, branch, abort=True)
134 if not rebase_ret.success:
134 # TODO(iannucci): Find collapsible branches in a smarter way? 135 # TODO(iannucci): Find collapsible branches in a smarter way?
135 print "Failed! Attempting to squash", branch, "...", 136 print "Failed! Attempting to squash", branch, "...",
136 squash_branch = branch+"_squash_attempt" 137 squash_branch = branch+"_squash_attempt"
137 git.run('checkout', '-b', squash_branch) 138 git.run('checkout', '-b', squash_branch)
138 git.squash_current_branch(merge_base=start_hash) 139 git.squash_current_branch(merge_base=start_hash)
139 140
140 # Try to rebase the branch_squash_attempt branch to see if it's empty. 141 # Try to rebase the branch_squash_attempt branch to see if it's empty.
141 squash_ret = git.rebase(parent, start_hash, squash_branch, abort=True) 142 squash_ret = git.rebase(parent, start_hash, squash_branch, abort=True)
142 empty_rebase = git.hash_one(squash_branch) == git.hash_one(parent) 143 empty_rebase = git.hash_one(squash_branch) == git.hash_one(parent)
143 git.run('checkout', branch) 144 git.run('checkout', branch)
144 git.run('branch', '-D', squash_branch) 145 git.run('branch', '-D', squash_branch)
145 if squash_ret.success and empty_rebase: 146 if squash_ret.success and empty_rebase:
146 print 'Success!' 147 print 'Success!'
147 git.squash_current_branch(merge_base=start_hash) 148 git.squash_current_branch(merge_base=start_hash)
148 git.rebase(parent, start_hash, branch) 149 git.rebase(parent, start_hash, branch)
149 else: 150 else:
150 # rebase and leave in mid-rebase state. 151 # rebase and leave in mid-rebase state.
151 git.rebase(parent, start_hash, branch) 152 # This second rebase attempt should always fail in the same
153 # way that the first one does. If it magically succeeds then
154 # something very strange has happened.
155 second_rebase_ret = git.rebase(parent, start_hash, branch)
156 assert(not second_rebase_ret.success)
iannucci 2014/10/13 17:41:39 I would actually throw an AssertionError with the
152 print "Failed!" 157 print "Failed!"
153 print 158 print
154 print "Here's what git-rebase had to say:" 159 print "Here's what git-rebase (squashed) had to say:"
155 print squash_ret.message
156 print 160 print
161 print squash_ret.stdout
162 print squash_ret.stderr
157 print textwrap.dedent( 163 print textwrap.dedent(
158 """ 164 """\
159 Squashing failed. You probably have a real merge conflict. 165 Squashing failed. You probably have a real merge conflict.
160 166
161 Your working copy is in mid-rebase. Either: 167 Your working copy is in mid-rebase. Either:
162 * completely resolve like a normal git-rebase; OR 168 * completely resolve like a normal git-rebase; OR
163 * abort the rebase and mark this branch as dormant: 169 * abort the rebase and mark this branch as dormant:
164 git config branch.%s.dormant true 170 git config branch.%s.dormant true
165 171
166 And then run `git rebase-update` again to resume. 172 And then run `git rebase-update` again to resume.
167 """ % branch) 173 """ % branch)
168 return False 174 return False
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 % (return_branch, root_branch) 258 % (return_branch, root_branch)
253 ) 259 )
254 git.run('checkout', root_branch) 260 git.run('checkout', root_branch)
255 git.set_config(STARTING_BRANCH_KEY, '') 261 git.set_config(STARTING_BRANCH_KEY, '')
256 262
257 return retcode 263 return retcode
258 264
259 265
260 if __name__ == '__main__': # pragma: no cover 266 if __name__ == '__main__': # pragma: no cover
261 sys.exit(main(sys.argv[1:])) 267 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « git_common.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698