From 2451ee476dfa0f94b3443455af612a56fc06c2c9 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Wed, 12 Feb 2025 17:18:29 -0800 Subject: [PATCH] Reland: add a `--no-squash` argument to `git rebase-update` See crbug.com/40264739 for many more details. But a prior attempt to land this patch resulted in [1] which simply removed all squashing behavior from `git rebase-update`. That broke several people's workflows. So this patch attempts, again, to simply add an opt-in to *not* squashing, for the folks (like me) who do not want that behavior. [1] https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6104282 Fixed: 40264739 Change-Id: I4a6aa8e53e854a7e601a0fb83f4f9fcb638d36ed Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6254099 Reviewed-by: Mason Freed Commit-Queue: Mason Freed Reviewed-by: Josip Sokcevic Auto-Submit: Mason Freed --- git_rebase_update.py | 13 ++++++++++--- man/html/git-rebase-update.html | 10 +++++++++- man/man1/git-rebase-update.1 | 7 ++++++- man/src/git-rebase-update.txt | 5 ++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/git_rebase_update.py b/git_rebase_update.py index 46d16064e6..32e5627610 100755 --- a/git_rebase_update.py +++ b/git_rebase_update.py @@ -140,7 +140,7 @@ def remove_empty_branches(branch_tree): 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', branch, git.hash_one(branch), parent, git.hash_one(parent), start_hash) @@ -161,7 +161,8 @@ def rebase_branch(branch, parent, start_hash): if git.hash_one(parent) != start_hash: # Try a plain rebase first print('Rebasing:', branch) - consider_squashing = git.get_num_commits(branch) != 1 + consider_squashing = git.get_num_commits(branch) != 1 and not ( + no_squash) rebase_ret = git.rebase(parent, start_hash, branch, @@ -275,6 +276,11 @@ def main(args=None): '-e', action='store_true', help='Do not automatically delete empty branches.') + parser.add_argument( + '--no-squash', + action='store_true', + help='Will not try to squash branches if rebasing fails.') + opts = parser.parse_args(args) if opts.verbose: # pragma: no cover @@ -341,7 +347,8 @@ def main(args=None): if git.is_dormant(branch): print('Skipping dormant branch', branch) else: - ret = rebase_branch(branch, parent, merge_base[branch]) + ret = rebase_branch(branch, parent, merge_base[branch], + opts.no_squash) if not ret: retcode = 1 diff --git a/man/html/git-rebase-update.html b/man/html/git-rebase-update.html index 5e01291e06..d8925185c1 100644 --- a/man/html/git-rebase-update.html +++ b/man/html/git-rebase-update.html @@ -756,7 +756,7 @@ git-rebase-update(1) Manual Page

SYNOPSIS

-
git rebase-update [-v | --verbose] [-n | --no-fetch] [-k | --keep-going]
+
git rebase-update [-v | --verbose] [-n | --no-fetch] [-k | --keep-going] [--no-squash]
@@ -869,6 +869,14 @@ Restoration

+--no-squash +
+
+

+ Skip the squash phase of rebase-update if there are merge conflicts. +

+
+
-v
diff --git a/man/man1/git-rebase-update.1 b/man/man1/git-rebase-update.1 index 8ff3c5bf1c..7381e3f48d 100644 --- a/man/man1/git-rebase-update.1 +++ b/man/man1/git-rebase-update.1 @@ -32,7 +32,7 @@ git-rebase-update \- Updates all branches to have the latest changes from their .SH "SYNOPSIS" .sp .nf -\fIgit rebase\-update\fR [\-v | \-\-verbose] [\-n | \-\-no\-fetch] [\-k | \-\-keep\-going] +\fIgit rebase\-update\fR [\-v | \-\-verbose] [\-n | \-\-no\-fetch] [\-k | \-\-keep\-going] | [\-\-no\-squash] .fi .sp .SH "DESCRIPTION" @@ -125,6 +125,11 @@ Skip the phase of rebase\-update\&. .RE .PP +\-\-no\-squash +.RS 4 +Skip the squashing phase of rebase\-update\&. +.RE +.PP \-v, \-\-verbose .RS 4 More text than your terminal can handle\&. diff --git a/man/src/git-rebase-update.txt b/man/src/git-rebase-update.txt index 3f07fdc5ea..a92fb38e4c 100644 --- a/man/src/git-rebase-update.txt +++ b/man/src/git-rebase-update.txt @@ -9,7 +9,7 @@ include::_git-rebase-update_desc.helper.txt[] SYNOPSIS -------- [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 ----------- @@ -78,6 +78,9 @@ OPTIONS --no-fetch:: Skip the `git fetch` phase of rebase-update. +--no-squash:: + Skip the squash phase of rebase-update if there are merge conflicts. + -v:: --verbose:: More text than your terminal can handle.