- 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 rev %s is an ancestor of ref "%s"', rev, ref)
+ process = subprocess.run(
+ ['git', '-C', cachedir, 'merge-base', '--is-ancestor', rev, ref], check=False)
+ return process.returncode == 0
+
+
+def verify_ancestry(repo: Repo, ref: Ref, rev: Rev) -> None:
+ if not is_ancestor(repo, ref, rev):
+ raise Exception('Rev %s is not an ancestor of ref "%s"' % (rev, ref))
+
+
+@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)