Skip to content

Commit ac22fd3

Browse files
authored
Fix benchsuite issue with newer versions of git (#15069)
This fixes a problem introduced with git 2.48.0 where the benchsuite would fail to run. The problem is that 2.48 changed the behavior so that HEAD would get changed to follow the remote. crates.io-index's default branch is "main". The benchsuite uses git to initialize the bare repo with a HEAD of "refs/heads/master" (the default of `init.defaultBranch`). Older versions of git would leave HEAD untouched, but newer versions update it to "refs/heads/main" after fetching to match the remote. This causes cargo to try to clone a branch called "main" which is empty. The solution here is to just force HEAD to be main, and use that as the branch for our time-travelling snapshot. Tested with git 2.47.0 and 2.48.1. Test is roughly: ``` rm -rf target/tmp/bench ; cargo test -p benchsuite --all-targets -- cargo && cargo test -p benchsuite --all-targets -- cargo` ``` (Run it twice to verify it can do an incremental fetch.)
2 parents 1b77ac6 + 5ac521c commit ac22fd3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

benches/benchsuite/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ impl Fixtures {
125125
}
126126
} else {
127127
fs::create_dir_all(&index).unwrap();
128-
git("init --bare");
128+
// git 2.48.0 changed the behavior of setting HEAD when doing a
129+
// fetch, so let's just force it to match
130+
// crates.io-index-archive's default branch. This also accounts
131+
// for users who may override init.defaultBranch.
132+
git("init --bare --initial-branch=main");
129133
git("remote add origin https://github.com/rust-lang/crates.io-index-archive");
130134
}
131135
git(&format!("fetch origin {}", CRATES_IO_COMMIT));
132-
git("branch -f master FETCH_HEAD");
136+
git("branch -f main FETCH_HEAD");
133137
}
134138

135139
/// This unpacks the compressed workspace skeletons into tmp/workspaces.

0 commit comments

Comments
 (0)