- logging.debug('Verifying rev %s is an ancestor of ref "%s"', rev, ref)
- subprocess.run(['git', '-C', cachedir, 'merge-base', '--is-ancestor',
- rev, ref], check=True)
+ logging.debug('Checking if %s is an ancestor of %s', ancestor, descendant)
+ process = subprocess.run(['git',
+ '-C',
+ cachedir,
+ 'merge-base',
+ '--is-ancestor',
+ ancestor,
+ descendant],
+ check=False)
+ return process.returncode == 0
+
+
+def verify_ancestry(
+ repo: Repo,
+ descendant: RefOrRev,
+ ancestor: RefOrRev) -> None:
+ if not is_ancestor(repo, descendant, ancestor):
+ raise Exception('%s is not an ancestor of %s' % (ancestor, descendant))
+
+
+@backoff.on_exception(
+ backoff.expo,
+ subprocess.CalledProcessError,
+ max_time=lambda: int(os.environ.get('BACKOFF_MAX_TIME', '30')))
+def _git_fetch(cachedir: Path, repo: Repo, ref: Ref) -> None:
+ # We don't use --force here because we want to abort and freak out if forced
+ # updates are happening.
+ subprocess.run(['git', '-C', cachedir, 'fetch', repo,
+ '%s:%s' % (ref, ref)], check=True)