From 8ba38ff4dc55c73058cfce64690d6ac2ca1b31c8 Mon Sep 17 00:00:00 2001 From: "pgervais@chromium.org" Date: Thu, 11 Jun 2015 21:41:25 +0000 Subject: [PATCH] Added message when upstream branch is gone. BUG=496892 Review URL: https://codereview.chromium.org/1156223008 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295634 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 13 ++++++++++++- tests/git_cl_test.py | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/git_cl.py b/git_cl.py index 7c3f530b7c..60fd1ce711 100755 --- a/git_cl.py +++ b/git_cl.py @@ -139,6 +139,13 @@ def IsGitVersionAtLeast(min_version): LooseVersion(version[len(prefix):]) >= LooseVersion(min_version)) +def BranchExists(branch): + """Return True if specified branch exists.""" + code, _ = RunGitWithCode(['rev-parse', '--verify', branch], + suppress_stderr=True) + return not code + + def ask_for_data(prompt): try: return raw_input(prompt) @@ -719,8 +726,12 @@ or verify this branch is set up to track another (via the --track argument to return remote, upstream_branch def GetCommonAncestorWithUpstream(self): + upstream_branch = self.GetUpstreamBranch() + if not BranchExists(upstream_branch): + DieWithError('The upstream for the current branch (%s) does not exist ' + 'anymore.\nPlease fix it and try again.' % self.GetBranch()) return git_common.get_or_create_merge_base(self.GetBranch(), - self.GetUpstreamBranch()) + upstream_branch) def GetUpstreamBranch(self): if self.upstream_branch is None: diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index cb87bdb4c6..b19e45c90d 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -86,6 +86,7 @@ class TestGitCl(TestCase): self.mock(git_common, 'get_or_create_merge_base', lambda *a: ( self._mocked_call(['get_or_create_merge_base']+list(a)))) + self.mock(git_cl, 'BranchExists', lambda _: True) self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '') self.mock(git_cl, 'ask_for_data', self._mocked_call) self.mock(git_cl.breakpad, 'post', self._mocked_call)