Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Use a bare clone for the staged git checkout

+28 -13
+23 -13
compiler-cli/src/dependencies.rs
··· 1174 1174 /// ``` 1175 1175 /// 1176 1176 /// For a package in a subdirectory of its repository the repository is 1177 - /// instead cloned into `build/git/<repo-name>-<hash>` without ever populating 1178 - /// its worktree, and the package is checked out into a transient staging 1177 + /// instead cloned into `build/git/<repo-name>-<hash>` as a bare repository 1178 + /// with no work tree, and the package is checked out into a transient staging 1179 1179 /// worktree which the subdirectory is hard-linked out of: 1180 1180 /// 1181 1181 /// ```sh 1182 - /// git init 1182 + /// git init --bare 1183 1183 /// git remote remove origin 1184 1184 /// git remote add origin <repo> 1185 1185 /// git fetch origin ··· 1232 1232 project_paths: &ProjectPaths, 1233 1233 ) -> Result<GitCheckout, Error> { 1234 1234 let clone_path = project_paths.build_packages_package(package_name); 1235 - prepare_git_clone(&clone_path, repo)?; 1235 + prepare_git_clone(&clone_path, repo, false)?; 1236 1236 let _ = execute_command(git_command(&clone_path).arg("checkout").arg(ref_))?; 1237 1237 let output = execute_command(git_command(&clone_path).arg("rev-parse").arg("HEAD"))?; 1238 1238 let commit = git_stdout(output); ··· 1248 1248 subdir: &Utf8Path, 1249 1249 ) -> Result<GitCheckout, Error> { 1250 1250 let clone_path = project_paths.build_git_repo(&git_repo_dir_name(repo)); 1251 - prepare_git_clone(&clone_path, repo)?; 1251 + prepare_git_clone(&clone_path, repo, true)?; 1252 1252 1253 1253 let commit = resolve_git_ref(&clone_path, repo, ref_)?; 1254 1254 ··· 1292 1292 } 1293 1293 1294 1294 /// Initialise (or reuse) a git clone at the given path and fetch from the 1295 - /// remote repository. 1296 - fn prepare_git_clone(clone_path: &Utf8Path, repo: &str) -> Result<()> { 1297 - // If the clone path exists but is not inside a git work tree, we need to 1298 - // remove the directory because running `git init` in a non-empty directory 1299 - // followed by `git checkout ...` is an error. See 1300 - // https://github.com/gleam-lang/gleam/issues/4488 for details. 1301 - if !fs::is_git_work_tree_root(clone_path) { 1295 + /// remote repository. When `bare` is set the clone is a bare repository with 1296 + /// no work tree. 1297 + fn prepare_git_clone(clone_path: &Utf8Path, repo: &str, bare: bool) -> Result<()> { 1298 + // If the clone path exists but is not the kind of git repo we expect, we 1299 + // need to remove the directory. 1300 + let reusable = if bare { 1301 + fs::is_bare_git_repo_root(clone_path) 1302 + } else { 1303 + fs::is_git_work_tree_root(clone_path) 1304 + }; 1305 + 1306 + if !reusable { 1302 1307 fs::delete_directory(clone_path)?; 1303 1308 } 1304 1309 1305 1310 fs::mkdir(clone_path)?; 1306 1311 1307 - let _ = execute_command(git_command(clone_path).arg("init"))?; 1312 + let mut init = git_command(clone_path); 1313 + let _ = init.arg("init"); 1314 + if bare { 1315 + let _ = init.arg("--bare"); 1316 + } 1317 + let _ = execute_command(&mut init)?; 1308 1318 1309 1319 // If this directory already exists, but the remote URL has been edited in 1310 1320 // `gleam.toml` without a `gleam clean`, `git remote add` will fail, causing
+5
compiler-cli/src/fs.rs
··· 833 833 exists(path.join(".git")).unwrap_or(false) 834 834 } 835 835 836 + pub(crate) fn is_bare_git_repo_root(path: &Utf8Path) -> bool { 837 + tracing::debug!(path=?path, "checking_for_bare_git_repo_root"); 838 + exists(path.join("HEAD")).unwrap_or(false) && exists(path.join("objects")).unwrap_or(false) 839 + } 840 + 836 841 /// Run `git init` in the given path. 837 842 /// If git is not installed then we do nothing. 838 843 pub fn git_init(path: &Utf8Path) -> Result<(), Error> {