Add a fallback to origin/trunk too when the branch is not tracked.
Raise an exception in case an upstream branch can't be found.
Fix an exception that was occuring just before when no upstream is found.
Review URL: http://codereview.chromium.org/1755018
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@46011 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/scm.py b/scm.py
index c483411..a9b1ecf 100644
--- a/scm.py
+++ b/scm.py
@@ -218,21 +218,30 @@
# Fall back on trying a git-svn upstream branch.
if GIT.IsGitSvn(cwd):
upstream_branch = GIT.GetSVNBranch(cwd)
- # Fall back on origin/master if it exits.
- elif GIT.Capture(['branch', '-r'], in_directory=cwd
- )[0].split().count('origin/master'):
- remote = 'origin'
- upstream_branch = 'refs/heads/master'
else:
- remote = None
- upstream_branch = None
+ # Else, try to guess the origin remote.
+ remote_branches = GIT.Capture(
+ ['branch', '-r'], in_directory=cwd)[0].split()
+ if 'origin/master' in remote_branches:
+ # Fall back on origin/master if it exits.
+ remote = 'origin'
+ upstream_branch = 'refs/heads/master'
+ elif 'origin/trunk' in remote_branches:
+ # Fall back on origin/trunk if it exists. Generally a shared
+ # git-svn clone
+ remote = 'origin'
+ upstream_branch = 'refs/heads/trunk'
+ else:
+ # Give up.
+ remote = None
+ upstream_branch = None
return remote, upstream_branch
@staticmethod
def GetUpstreamBranch(cwd):
"""Gets the current branch's upstream branch."""
remote, upstream_branch = GIT.FetchUpstreamTuple(cwd)
- if remote != '.':
+ if remote != '.' and upstream_branch:
upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote)
return upstream_branch