diff --git a/scm.py b/scm.py index c4834116f..a9b1ecf84 100644 --- a/scm.py +++ b/scm.py @@ -218,21 +218,30 @@ class GIT(object): # 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 diff --git a/trychange.py b/trychange.py index 644a55a91..cf60b3cff 100755 --- a/trychange.py +++ b/trychange.py @@ -216,9 +216,10 @@ class GIT(SCM): if not self.diff_against: self.diff_against = scm.GIT.GetUpstreamBranch(self.checkout_root) if not self.diff_against: - print "Unable to determine default branch to diff against." - print "Verify this branch is set up to track another" - print "(via the --track argument to \"git checkout -b ...\"" + raise NoTryServerAccess( + "Unable to determine default branch to diff against. " + "Verify this branch is set up to track another" + "(via the --track argument to \"git checkout -b ...\"") logging.info("GIT(%s)" % self.checkout_root) def ReadRootFile(self, filename):