diff --git a/gclient_scm.py b/gclient_scm.py index 9196f680c..3b1b59f7a 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -495,7 +495,7 @@ class GitWrapper(SCMWrapper): self.Print('Will cherrypick %r .. %r on top of %r.' % ( target_rev, pr, base_rev)) try: - if scm.GIT.IsAncestor(self.checkout_path, pr, target_rev): + if scm.GIT.IsAncestor(pr, target_rev, cwd=self.checkout_path): if len(patch_revs_to_process) > 1: # If there are multiple patch_revs_to_process then we do not want # want to invalidate a previous patch so throw an error. diff --git a/git_cl.py b/git_cl.py index c6a9bb300..b1eafde67 100755 --- a/git_cl.py +++ b/git_cl.py @@ -4668,12 +4668,12 @@ def _UploadAllPrecheck(options, orig_args): # Case 4: If upstream's last_upload < cl.base_commit we are # uploading cl and upstream_cl. # Continue up the tree to check other branch relations. - if scm.GIT.IsAncestor(None, upstream_last_upload, base_commit): + if scm.GIT.IsAncestor(upstream_last_upload, base_commit): continue # Case 5: If cl.base_commit < upstream's last_upload the user # must rebase before uploading. - if scm.GIT.IsAncestor(None, base_commit, upstream_last_upload): + if scm.GIT.IsAncestor(base_commit, upstream_last_upload): DieWithError( 'At least one branch in the stack has diverged from its upstream ' 'branch and does not contain its upstream\'s last upload.\n' diff --git a/scm.py b/scm.py index 8368bd010..4013a7625 100644 --- a/scm.py +++ b/scm.py @@ -314,7 +314,8 @@ class GIT(object): return upstream_branch @staticmethod - def IsAncestor(cwd, maybe_ancestor, ref): + def IsAncestor(maybe_ancestor, ref, cwd=None): + # type: (string, string, Optional[string]) -> bool """Verifies if |maybe_ancestor| is an ancestor of |ref|.""" try: GIT.Capture(['merge-base', '--is-ancestor', maybe_ancestor, ref], cwd=cwd) diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 0eb5b675e..52d560d3c 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -159,12 +159,15 @@ class RealGitTest(fake_repos.FakeReposTestBase): self.assertTrue(scm.GIT.IsValidRevision(cwd=self.cwd, rev='HEAD')) def testIsAncestor(self): - self.assertTrue(scm.GIT.IsAncestor( - self.cwd, self.githash('repo_1', 1), self.githash('repo_1', 2))) - self.assertFalse(scm.GIT.IsAncestor( - self.cwd, self.githash('repo_1', 2), self.githash('repo_1', 1))) - self.assertFalse(scm.GIT.IsAncestor( - self.cwd, self.githash('repo_1', 1), 'zebra')) + self.assertTrue( + scm.GIT.IsAncestor(self.githash('repo_1', 1), + self.githash('repo_1', 2), + cwd=self.cwd)) + self.assertFalse( + scm.GIT.IsAncestor(self.githash('repo_1', 2), + self.githash('repo_1', 1), + cwd=self.cwd)) + self.assertFalse(scm.GIT.IsAncestor(self.githash('repo_1', 1), 'zebra')) def testGetAllFiles(self): self.assertEqual(['DEPS','origin'], scm.GIT.GetAllFiles(self.cwd))