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