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
experimental/szager/collated-output
maruel@chromium.org 15 years ago
parent 81e012ce41
commit a630bd7e2c

@ -218,12 +218,21 @@ class GIT(object):
# Fall back on trying a git-svn upstream branch. # Fall back on trying a git-svn upstream branch.
if GIT.IsGitSvn(cwd): if GIT.IsGitSvn(cwd):
upstream_branch = GIT.GetSVNBranch(cwd) upstream_branch = GIT.GetSVNBranch(cwd)
else:
# 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. # Fall back on origin/master if it exits.
elif GIT.Capture(['branch', '-r'], in_directory=cwd
)[0].split().count('origin/master'):
remote = 'origin' remote = 'origin'
upstream_branch = 'refs/heads/master' 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: else:
# Give up.
remote = None remote = None
upstream_branch = None upstream_branch = None
return remote, upstream_branch return remote, upstream_branch
@ -232,7 +241,7 @@ class GIT(object):
def GetUpstreamBranch(cwd): def GetUpstreamBranch(cwd):
"""Gets the current branch's upstream branch.""" """Gets the current branch's upstream branch."""
remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) remote, upstream_branch = GIT.FetchUpstreamTuple(cwd)
if remote != '.': if remote != '.' and upstream_branch:
upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote)
return upstream_branch return upstream_branch

@ -216,9 +216,10 @@ class GIT(SCM):
if not self.diff_against: if not self.diff_against:
self.diff_against = scm.GIT.GetUpstreamBranch(self.checkout_root) self.diff_against = scm.GIT.GetUpstreamBranch(self.checkout_root)
if not self.diff_against: if not self.diff_against:
print "Unable to determine default branch to diff against." raise NoTryServerAccess(
print "Verify this branch is set up to track another" "Unable to determine default branch to diff against. "
print "(via the --track argument to \"git checkout -b ...\"" "Verify this branch is set up to track another"
"(via the --track argument to \"git checkout -b ...\"")
logging.info("GIT(%s)" % self.checkout_root) logging.info("GIT(%s)" % self.checkout_root)
def ReadRootFile(self, filename): def ReadRootFile(self, filename):

Loading…
Cancel
Save