From 6eeb55de1774313601cd3b80e3e205ebb6959ac1 Mon Sep 17 00:00:00 2001 From: Peter Birk Pakkenberg Date: Wed, 26 Jun 2024 20:14:23 +0000 Subject: [PATCH] Add --tree option to rebase-update. I often find myself working on stacked changes, and this option will make it easier to integrate changes into downstream CLs. With `git rebase-update --current --tree --no-fetch`, it is possible to only rebase the current chain of changes, without touching any other local branches that may exist. This is beneficial both for speed, and to avoid having to resolve merge conflicts on branches unrelated to the changes you are currently working on. Change-Id: I2d3853ad5aad6c74db0ae26ff8d27d14dcaed3e2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5546383 Auto-Submit: Peter Pakkenberg Commit-Queue: Scott Lee Reviewed-by: Scott Lee --- git_rebase_update.py | 18 ++++++++++++++++++ man/src/git-rebase-update.txt | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/git_rebase_update.py b/git_rebase_update.py index f2b47b894c..46d16064e6 100755 --- a/git_rebase_update.py +++ b/git_rebase_update.py @@ -232,6 +232,16 @@ def rebase_branch(branch, parent, start_hash): return True +def with_downstream_branches(base_branches, branch_tree): + """Returns a set of base_branches and all downstream branches.""" + downstream_branches = set() + for branch, parent in git.topo_iter(branch_tree): + if parent in base_branches or parent in downstream_branches: + downstream_branches.add(branch) + + return downstream_branches.union(base_branches) + + def main(args=None): if gclient_utils.IsEnvCog(): print( @@ -253,6 +263,10 @@ def main(args=None): parser.add_argument('--current', action='store_true', help='Only rebase the current branch.') + parser.add_argument('--tree', + action='store_true', + help='Rebase all branches downstream from the ' + 'selected branch(es).') parser.add_argument('branches', nargs='*', help='Branches to be rebased. All branches are assumed ' @@ -297,6 +311,10 @@ def main(args=None): branches_to_rebase.add(git.current_branch()) skipped, branch_tree = git.get_branch_tree(use_limit=not opts.current) + if opts.tree: + branches_to_rebase = with_downstream_branches(branches_to_rebase, + branch_tree) + if branches_to_rebase: skipped = set(skipped).intersection(branches_to_rebase) for branch in skipped: diff --git a/man/src/git-rebase-update.txt b/man/src/git-rebase-update.txt index e7c0c2d2fd..3f07fdc5ea 100644 --- a/man/src/git-rebase-update.txt +++ b/man/src/git-rebase-update.txt @@ -85,6 +85,10 @@ OPTIONS --current:: Only rebase the current branch. +--tree:: + Also rebase any branches downstream from the selected branches. Use with + named branches or `--current` to selectively rebase a branch tree. + CONFIGURATION VARIABLES -----------------------