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 <pbirk@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
changes/83/5546383/7
Peter Birk Pakkenberg 1 year ago committed by LUCI CQ
parent e6f497f72b
commit 6eeb55de17

@ -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:

@ -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
-----------------------

Loading…
Cancel
Save