Use get_or_create_merge_base in git-cl-upload to correctly deal with rebased

upstreams.

In the event that users are NOT using the enhanced tooling, this is equivalent
to `git merge-base "@{u}" HEAD`. In the event that they are, this will catch
the case where their parent branch got rebased, but this branch hasn't been
rebased on the parent yet.

R=agable@chromium.org, szager@chromium.org
BUG=

Review URL: https://codereview.chromium.org/224703002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@261601 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
iannucci@chromium.org 11 years ago
parent f2fb5e7f8c
commit 9e849276a0

@ -35,13 +35,14 @@ import breakpad # pylint: disable=W0611
import clang_format
import fix_encoding
import gclient_utils
import git_common
import owners_finder
import presubmit_support
import rietveld
import scm
import subcommand
import subprocess2
import watchlists
import owners_finder
__version__ = '1.0'
@ -551,7 +552,8 @@ or verify this branch is set up to track another (via the --track argument to
return remote, upstream_branch
def GetCommonAncestorWithUpstream(self):
return RunGit(['merge-base', self.GetUpstreamBranch(), 'HEAD']).strip()
return git_common.get_or_create_merge_base(self.GetBranch(),
self.GetUpstreamBranch())
def GetUpstreamBranch(self):
if self.upstream_branch is None:
@ -2155,7 +2157,7 @@ def CMDtry(parser, args):
"-bwin_rel:base_unittests:ValuesTest.*Value"))
group.add_option(
"-m", "--master", default='',
help=("Specify a try master where to run the tries."))
help=("Specify a try master where to run the tries."))
group.add_option(
"-r", "--revision",
help="Revision to use for the try job; default: the "

@ -16,6 +16,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from testing_support.auto_stub import TestCase
import git_cl
import git_common
import subprocess2
@ -76,6 +77,9 @@ class TestGitCl(TestCase):
self.mock(subprocess2, 'check_output', self._mocked_call)
self.mock(subprocess2, 'communicate', self._mocked_call)
self.mock(subprocess2, 'Popen', self._mocked_call)
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, 'FindCodereviewSettingsFile', lambda: '')
self.mock(git_cl, 'ask_for_data', self._mocked_call)
self.mock(git_cl.breakpad, 'post', self._mocked_call)
@ -93,7 +97,7 @@ class TestGitCl(TestCase):
self.assertEquals([], self.calls)
super(TestGitCl, self).tearDown()
def _mocked_call(self, *args, **kwargs):
def _mocked_call(self, *args, **_kwargs):
self.assertTrue(
self.calls,
'@%d Expected: <Missing> Actual: %r' % (self._calls_done, args))
@ -158,7 +162,7 @@ class TestGitCl(TestCase):
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git', 'merge-base', 'master', 'HEAD'],),
((['get_or_create_merge_base', 'master', 'master'],),
'fake_ancestor_sha'),
] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
((['git', 'rev-parse', '--show-cdup'],), ''),
@ -538,8 +542,8 @@ class TestGitCl(TestCase):
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.merge'],), 'master'),
((['git', 'config', 'branch.master.remote'],), 'origin'),
((['git',
'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'),
((['get_or_create_merge_base', 'master', 'master'],),
'fake_ancestor_sha'),
] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
((['git', 'rev-parse', '--show-cdup'],), ''),
((['git', 'rev-parse', 'HEAD'],), '12345'),

Loading…
Cancel
Save