git-cl: Use scm.GIT.FetchUpstreamTuple.
scm:
- Add methods to deal with git configs and tests for them.
Will make it easier to mock git config calls as opposed
to all git calls.
- Add tests to FetchUpstreamTuple
git-cl:
- Mock out settings.GetChangeRoot()
- Use scm.GIT.FetchUpstreamTuple() to reduce code duplication,
and mock it out on tests.
Bug: 1051631
Change-Id: I1a3220b4c0f3e6221b3c00550259a433c2775798
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2052552
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
diff --git a/git_cl.py b/git_cl.py
index e53e8af..78ca488 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1194,30 +1194,15 @@
"""Returns a tuple containing remote and remote ref,
e.g. 'origin', 'refs/heads/master'
"""
- remote = '.'
- upstream_branch = _git_get_branch_config_value('merge', branch=branch)
-
- if upstream_branch:
- remote = _git_get_branch_config_value('remote', branch=branch)
- else:
- upstream_branch = RunGit(['config', 'rietveld.upstream-branch'],
- error_ok=True).strip()
- if upstream_branch:
- remote = RunGit(['config', 'rietveld.upstream-remote']).strip()
- else:
- # Else, try to guess the origin remote.
- remote_branches = RunGit(['branch', '-r']).split()
- if 'origin/master' in remote_branches:
- # Fall back on origin/master if it exits.
- remote = 'origin'
- upstream_branch = 'refs/heads/master'
- else:
- DieWithError(
- 'Unable to determine default branch to diff against.\n'
- 'Either pass complete "git diff"-style arguments, like\n'
- ' git cl upload origin/master\n'
- 'or verify this branch is set up to track another \n'
- '(via the --track argument to "git checkout -b ...").')
+ remote, upstream_branch = scm.GIT.FetchUpstreamTuple(
+ settings.GetRoot(), branch)
+ if not remote or not upstream_branch:
+ DieWithError(
+ 'Unable to determine default branch to diff against.\n'
+ 'Either pass complete "git diff"-style arguments, like\n'
+ ' git cl upload origin/master\n'
+ 'or verify this branch is set up to track another \n'
+ '(via the --track argument to "git checkout -b ...").')
return remote, upstream_branch