Skip to content

The agent that grows with you

perf(install): a pinned install checks out only the pin, not the branch tip first

kshitijk4poor2f6716dd7dc9
diff --git a/scripts/install.sh b/scripts/install.sh
index 3fa829d1ecc..da348e9bd56 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -658,8 +658,10 @@ stage_repository() {
# checkout and history walk (#129712).
label="Cloning $REPO_URL ($BRANCH) into $INSTALL_DIR"
[ "$attempt" = 1 ] || label="$label (attempt $attempt of 3)"
+ # A pinned install checks out only the pin: materializing the branch tip
+ # first fetches and writes every file twice.
if run_logged "$label" git clone ${progress[@]+"${progress[@]}"} \
- --filter=blob:none --branch "$BRANCH" "$REPO_URL" "$staged/tree"; then
+ --filter=blob:none ${INSTALL_COMMIT:+--no-checkout} --branch "$BRANCH" "$REPO_URL" "$staged/tree"; then
cloned=true
break
fi
diff --git a/tests/scripts/install/test_install_sh_repository_stage.py b/tests/scripts/install/test_install_sh_repository_stage.py
index 4d0da0c4ec5..ad562b16922 100644
--- a/tests/scripts/install/test_install_sh_repository_stage.py
+++ b/tests/scripts/install/test_install_sh_repository_stage.py
@@ -97,6 +97,35 @@ def test_commit_pin_must_come_from_the_installed_branch(tmp_path):
assert _git(tmp_path / "install", "rev-parse", "HEAD") == on_branch
+def test_pinned_fresh_clone_never_materializes_the_branch_tip(tmp_path):
+ """A pinned install (the desktop bootstrap passes --commit) checks out only the pin.
+
+ Every file the tip changed is fetched and written once for the tip, then again for the pin.
+ """
+ origin = _origin(tmp_path / "origin")
+ pin = _git(origin, "rev-parse", "HEAD")
+ _commit(origin, "tip")
+ _git(origin, "config", "uploadpack.allowFilter", "true")
+ trace = tmp_path / "trace.log"
+ tracer = f'git() {{ printf "%s\\n" "$*" >> {shlex.quote(trace.as_posix())}; command git "$@"; }}'
+ result = _stage(tmp_path, origin, commit=pin, prelude=tracer)
+ assert result.returncode == 0, result.stdout + result.stderr
+ install = tmp_path / "install"
+ assert _git(install, "rev-parse", "HEAD") == pin
+ assert (install / "README").read_text() == "one"
+ assert _git(install, "status", "--porcelain") == ""
+ [clone] = [line for line in trace.read_text().splitlines() if line.startswith("clone ")]
+ assert "--no-checkout" in clone.split()
+ unpinned_root = tmp_path / "unpinned"
+ unpinned_root.mkdir()
+ trace.unlink()
+ result = _stage(unpinned_root, origin, prelude=tracer)
+ assert result.returncode == 0, result.stdout + result.stderr
+ assert (unpinned_root / "install" / "README").read_text() == "tip"
+ [clone] = [line for line in trace.read_text().splitlines() if line.startswith("clone ")]
+ assert "--no-checkout" not in clone.split()
+
+
def test_commitless_checkout_is_moved_aside_and_recloned(tmp_path):
origin = _origin(tmp_path / "origin")
install = tmp_path / "install"