From 5819446364e869d64b3811b3cf7e81e9bf10c9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Fri, 27 Aug 2021 17:36:16 +0000 Subject: [PATCH] git-cl: add --upstream to git cl format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is occasionally useful to be able to run git cl format against some specific upstream without having to configure branches in git. As CMDformat can't easily take "git-diff-like" args, add an explict --upstream argument. This has come up a few times in the past and hopefuly the new arg will be discoverable enough in --help for git cl format to help people. Bug: 832295, 1082520 Change-Id: I2f3a33d719104ffd97cfa388178e38bfe8731c0e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3124674 Reviewed-by: Josip Sokcevic Commit-Queue: Tomasz Ĺšniatowski --- git_cl.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index a12483ac9..e801449f2 100755 --- a/git_cl.py +++ b/git_cl.py @@ -5088,6 +5088,7 @@ def CMDformat(parser, args): GN_EXTS = ['.gn', '.gni', '.typemap'] parser.add_option('--full', action='store_true', help='Reformat the full content of all touched files') + parser.add_option('--upstream', help='Branch to check against') parser.add_option('--dry-run', action='store_true', help='Don\'t modify any file on disk.') parser.add_option( @@ -5140,8 +5141,10 @@ def CMDformat(parser, args): # to cover the case where the user may have called "git fetch origin", # moving the origin branch to a newer commit, but hasn't rebased yet. upstream_commit = None - cl = Changelist() - upstream_branch = cl.GetUpstreamBranch() + upstream_branch = opts.upstream + if not upstream_branch: + cl = Changelist() + upstream_branch = cl.GetUpstreamBranch() if upstream_branch: upstream_commit = RunGit(['merge-base', 'HEAD', upstream_branch]) upstream_commit = upstream_commit.strip()