Add --no-squash argument to git rebase-update

--no-squash makes it faster to run rebase-update when there are merge
conflicts and you know that squashing will not help. For example, I
store all of my branches in one commit each, so I know that squashing
isn't even possible because they are already squashed.

Change-Id: I2679a855ad79d602a6d1ee09c140f2fd27ae20c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2904096
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
changes/96/2904096/4
Joey Arhar 3 years ago committed by LUCI CQ
parent 019e73a13b
commit 80cc67cc00

@ -141,7 +141,7 @@ def remove_empty_branches(branch_tree):
print(git.run('branch', '-d', branch)) print(git.run('branch', '-d', branch))
def rebase_branch(branch, parent, start_hash): def rebase_branch(branch, parent, start_hash, no_squash):
logging.debug('considering %s(%s) -> %s(%s) : %s', logging.debug('considering %s(%s) -> %s(%s) : %s',
branch, git.hash_one(branch), parent, git.hash_one(parent), branch, git.hash_one(branch), parent, git.hash_one(parent),
start_hash) start_hash)
@ -162,8 +162,18 @@ def rebase_branch(branch, parent, start_hash):
if git.hash_one(parent) != start_hash: if git.hash_one(parent) != start_hash:
# Try a plain rebase first # Try a plain rebase first
print('Rebasing:', branch) print('Rebasing:', branch)
rebase_ret = git.rebase(parent, start_hash, branch, abort=True) rebase_ret = git.rebase(parent, start_hash, branch, abort = not no_squash)
if not rebase_ret.success: if not rebase_ret.success:
if no_squash:
print(textwrap.dedent("""\
Your working copy is in mid-rebase. Either:
* completely resolve like a normal git-rebase; OR
* abort the rebase and mark this branch as dormant:
git config branch.%s.dormant true
And then run `git rebase-update` again to resume.
""" % branch))
return False
# TODO(iannucci): Find collapsible branches in a smarter way? # TODO(iannucci): Find collapsible branches in a smarter way?
print("Failed! Attempting to squash", branch, "...", end=' ') print("Failed! Attempting to squash", branch, "...", end=' ')
sys.stdout.flush() sys.stdout.flush()
@ -235,6 +245,9 @@ def main(args=None):
'if none specified.') 'if none specified.')
parser.add_argument('--keep-empty', '-e', action='store_true', parser.add_argument('--keep-empty', '-e', action='store_true',
help='Do not automatically delete empty branches.') help='Do not automatically delete empty branches.')
parser.add_argument(
'--no-squash', action='store_true',
help='Will not try to squash branches when rebasing fails.')
opts = parser.parse_args(args) opts = parser.parse_args(args)
if opts.verbose: # pragma: no cover if opts.verbose: # pragma: no cover
@ -295,7 +308,7 @@ def main(args=None):
if git.is_dormant(branch): if git.is_dormant(branch):
print('Skipping dormant branch', branch) print('Skipping dormant branch', branch)
else: else:
ret = rebase_branch(branch, parent, merge_base[branch]) ret = rebase_branch(branch, parent, merge_base[branch], opts.no_squash)
if not ret: if not ret:
retcode = 1 retcode = 1

@ -756,7 +756,7 @@ git-rebase-update(1) Manual Page
<h2 id="_synopsis">SYNOPSIS</h2> <h2 id="_synopsis">SYNOPSIS</h2>
<div class="sectionbody"> <div class="sectionbody">
<div class="verseblock"> <div class="verseblock">
<pre class="content"><em>git rebase-update</em> [-v | --verbose] [-n | --no-fetch] [-k | --keep-going]</pre> <pre class="content"><em>git rebase-update</em> [-v | --verbose] [-n | --no-fetch] [-k | --keep-going] [--no-squash]</pre>
<div class="attribution"> <div class="attribution">
</div></div> </div></div>
</div> </div>
@ -869,6 +869,14 @@ Restoration
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
--no-squash
</dt>
<dd>
<p>
Skip the squash phase of rebase-update when there are merge conflicts.
</p>
</dd>
<dt class="hdlist1">
-v -v
</dt> </dt>
<dt class="hdlist1"> <dt class="hdlist1">

@ -9,7 +9,7 @@ include::_git-rebase-update_desc.helper.txt[]
SYNOPSIS SYNOPSIS
-------- --------
[verse] [verse]
'git rebase-update' [-v | --verbose] [-n | --no-fetch] [-k | --keep-going] 'git rebase-update' [-v | --verbose] [-n | --no-fetch] [-k | --keep-going] [--no-squash]
DESCRIPTION DESCRIPTION
----------- -----------
@ -78,6 +78,9 @@ OPTIONS
--no-fetch:: --no-fetch::
Skip the `git fetch` phase of rebase-update. Skip the `git fetch` phase of rebase-update.
--no-squash::
Skip the squash phase of rebase-update when there are merge conflicts.
-v:: -v::
--verbose:: --verbose::
More text than your terminal can handle. More text than your terminal can handle.

Loading…
Cancel
Save