From e4a99d5551ff7808c4f735958a7b63951c17e5e9 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sun, 16 Aug 2026 12:57:23 -0400 Subject: [PATCH] fix(git): `git gc` with `safe.bareRepository=explicit` Git v3 will enforce `safe.bareRepository=explicit`, while older versions don't. See This ensures `git gc` work with `safe.bareRepository=explicit` by setting an explicit `GIT_DIR` environment variable. This is not a requirement of making CLI fetch the default, but better to have before Git CLI v3 is out. --- src/sources/git/utils.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sources/git/utils.rs b/src/sources/git/utils.rs index b4f07784d23..21996626098 100644 --- a/src/sources/git/utils.rs +++ b/src/sources/git/utils.rs @@ -1462,7 +1462,11 @@ fn maybe_gc_repo(repo: &mut git2::Repository, gctx: &GlobalContext) -> CargoResu if let Ok(limit) = gctx.get_env("__CARGO_PACKFILE_LIMIT") { cmd.arg(format!("-c gc.autoPackLimit={}", limit)); } - cmd.arg("gc").arg("--auto").current_dir(repo.path()); + cmd.arg("gc") + .arg("--auto") + // Explicitly set `GIT_DIR` so `safe.bareRepository=explicit` doesn't reject it. + .env("GIT_DIR", repo.path()) + .current_dir(repo.path()); match cmd.output() { Ok(out) => {