git-cl: add --upstream to git cl format

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 <sokcevic@google.com>
Commit-Queue: Tomasz Śniatowski <tsniatowski@vewd.com>
diff --git a/git_cl.py b/git_cl.py
index a12483a..e801449 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -5088,6 +5088,7 @@
   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 @@
   # 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()