Make cwd optional for scm.IsAncestor()

Bug:b/265929888
Change-Id: I9f25cd26eaf2d708ce3ac7d86503bb2c295c8406
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4178351
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Joanna Wang <jojwang@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
changes/51/4178351/8
Joanna Wang 3 years ago committed by LUCI CQ
parent 18de1f68e6
commit ab9c6ba27f

@ -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.

@ -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'

@ -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)

@ -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))

Loading…
Cancel
Save