diff --git a/server/code/app/index/compiler_tier.py b/server/code/app/index/compiler_tier.py index f20d34651b9..0b030e796fe 100644 --- a/server/code/app/index/compiler_tier.py +++ b/server/code/app/index/compiler_tier.py @@ -623,10 +623,13 @@ def resolve_binary(configured: str) -> Path: def checkout_fetch_args(bare: Path | str, target: str) -> list[str]: """`git` arguments that fetch `target` from the local bare clone into a checkout: no submodule recursion, and the commit recorded on - `SCIP_HEAD_REF` so the next fetch sends only what is new.""" + `SCIP_HEAD_REF` so the next fetch sends only what is new. A mirror of a remote + that serves truncated history is shallow, and without `--update-shallow` git + drops the ref and still exits 0.""" return [ "fetch", "--recurse-submodules=no", + "--update-shallow", *upload_pack_args(str(bare)), str(bare), f"+{target}:{SCIP_HEAD_REF}", diff --git a/tests/unit/test_scip_checkout_fetch_ref.py b/tests/unit/test_scip_checkout_fetch_ref.py index 6bfe1c98c45..0a275f8c199 100644 --- a/tests/unit/test_scip_checkout_fetch_ref.py +++ b/tests/unit/test_scip_checkout_fetch_ref.py @@ -134,3 +134,34 @@ async def test_a_local_remote_another_uid_owns_is_read(tmp_path: Path, monkeypat ) heads = await gitrepo.remote_branches(str(checkout / ".git"), str(bare)) assert heads["master"] == target + + +def _shallow_mirror(tmp_path: Path) -> tuple[Path, Path, Path]: + """(source, mirror, empty checkout) for a remote that serves only its last two + commits: the mirror, cloned from it without a depth as the bootstrap clones, is + shallow too.""" + src = tmp_path / "src" + src.mkdir() + _git(src, "init", "-q", "-b", "master") + _commits(src, 5, "base") + remote = tmp_path / "remote.git" + _git(tmp_path, "clone", "-q", "--bare", "--depth", "2", f"file://{src}", str(remote)) + mirror = tmp_path / "mirror.git" + _git(tmp_path, "clone", "-q", "--bare", "--no-local", str(remote), str(mirror)) + assert _git(mirror, "rev-parse", "--is-shallow-repository") == "true" + checkout = tmp_path / "checkout" + _git(tmp_path, "init", "-q", str(checkout)) + return src, mirror, checkout + + +def test_a_fetch_from_a_shallow_mirror_lands_on_the_ref(tmp_path: Path) -> None: + src, mirror, checkout = _shallow_mirror(tmp_path) + first = _git(mirror, "rev-parse", "master") + _git(checkout, *checkout_fetch_args(mirror, first)) + assert _git(checkout, "rev-parse", SCIP_HEAD_REF) == first + + second = _commits(src, 2, "next") + _git(src, "push", "-q", str(mirror), "master") + got = _received(checkout, checkout_fetch_args(mirror, second)) + assert _git(checkout, "rev-parse", SCIP_HEAD_REF) == second + assert got <= 2 * 3 # two commits: commit + tree + blob each, not the history