Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/code/app/index/compiler_tier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/test_scip_checkout_fetch_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading