diff --git a/git_common.py b/git_common.py index 91ddeb49a..e9b322004 100644 --- a/git_common.py +++ b/git_common.py @@ -530,7 +530,11 @@ def get_or_create_merge_base(branch, parent=None): parent = parent or upstream(branch) if parent is None or branch is None: return None - actual_merge_base = run('merge-base', parent, branch) + + try: + actual_merge_base = run('merge-base', '--fork-point', parent, branch) + except subprocess2.CalledProcessError: + actual_merge_base = run('merge-base', parent, branch) if base_upstream != parent: base = None diff --git a/tests/git_common_test.py b/tests/git_common_test.py index c382cdb16..e6e2f8344 100755 --- a/tests/git_common_test.py +++ b/tests/git_common_test.py @@ -692,6 +692,36 @@ class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase, self.assertIsNone( self.repo.run(self.gc.get_or_create_merge_base, 'branch_DOG')) + def testMergeBaseWithForkPoint(self): + self.repo.git('commit', '--allow-empty', '-am', 'foooooo') + self.repo.git('checkout','-tb', 'foobarA', 'master') + foobarA = self.repo.run(self.gc.hash_one, 'foobarA', short=True) + + self.repo.git('checkout','-tb', 'foobarB', 'foobarA') + with self.repo.open('cl1', 'w') as f: + f.write('cl1') + self.repo.git('add', 'cl1') + self.repo.git_commit('cl1') + foobarB_old = self.repo.run(self.gc.hash_one, 'foobarB', short=True) + + self.repo.git('checkout','-tb', 'foobarC', 'foobarB') + with self.repo.open('cl2', 'w') as f: + f.write('cl2') + self.repo.git('add', 'cl2') + self.repo.git_commit('cl2') + foobarC = self.repo.run(self.gc.hash_one, 'foobarC', short=True) + + self.repo.git('checkout', 'foobarB') + with self.repo.open('cl1', 'w') as f: + f.write('amend cl1') + self.repo.git('add', 'cl1') + self.repo.git('commit', '--amend', '-m', 'amend cl1') + + self.assertIn(foobarA, + self.repo.run(self.gc.get_or_create_merge_base, 'foobarB', foobarB_old)) + self.assertIn(foobarB_old, + self.repo.run(self.gc.get_or_create_merge_base, foobarC, 'foobarB')) + def testGetBranchTree(self): skipped, tree = self.repo.run(self.gc.get_branch_tree) # This check fails with git 2.4 (see crbug.com/487172)