···12321232 project_paths: &ProjectPaths,
12331233) -> Result<GitCheckout, Error> {
12341234 let clone_path = project_paths.build_packages_package(package_name);
12351235- prepare_git_clone(&clone_path, repo, false)?;
12351235+ prepare_git_clone(&clone_path, repo, CloneFormat::WorkTree)?;
12361236 let _ = execute_command(git_command(&clone_path).arg("checkout").arg(ref_))?;
12371237 let output = execute_command(git_command(&clone_path).arg("rev-parse").arg("HEAD"))?;
12381238 let commit = git_stdout(output);
···12481248 subdir: &Utf8Path,
12491249) -> Result<GitCheckout, Error> {
12501250 let clone_path = project_paths.build_git_repo(&git_repo_dir_name(repo));
12511251- prepare_git_clone(&clone_path, repo, true)?;
12511251+ prepare_git_clone(&clone_path, repo, CloneFormat::Bare)?;
1252125212531253 let commit = resolve_git_ref(&clone_path, repo, ref_)?;
12541254···12911291 })
12921292}
1293129312941294+#[derive(Clone, Copy)]
12951295+enum CloneFormat {
12961296+ /// A regular clone with a checked-out work tree.
12971297+ WorkTree,
12981298+ /// A bare repository with no work tree.
12991299+ Bare,
13001300+}
13011301+12941302/// Initialise (or reuse) a git clone at the given path and fetch from the
12951295-/// remote repository. When `bare` is set the clone is a bare repository with
12961296-/// no work tree.
12971297-fn prepare_git_clone(clone_path: &Utf8Path, repo: &str, bare: bool) -> Result<()> {
13031303+/// remote repository.
13041304+fn prepare_git_clone(clone_path: &Utf8Path, repo: &str, format: CloneFormat) -> Result<()> {
12981305 // If the clone path exists but is not the kind of git repo we expect, we
12991306 // need to remove the directory.
13001300- let reusable = if bare {
13011301- fs::is_bare_git_repo_root(clone_path)
13021302- } else {
13031303- fs::is_git_work_tree_root(clone_path)
13071307+ let reusable = match format {
13081308+ CloneFormat::Bare => fs::is_bare_git_repo_root(clone_path),
13091309+ CloneFormat::WorkTree => fs::is_git_work_tree_root(clone_path),
13041310 };
1305131113061312 if !reusable {
···1311131713121318 let mut init = git_command(clone_path);
13131319 let _ = init.arg("init");
13141314- if bare {
13201320+ if matches!(format, CloneFormat::Bare) {
13151321 let _ = init.arg("--bare");
13161322 }
13171323 let _ = execute_command(&mut init)?;