Skip to content

Commit 7aa570a

Browse files
authored
git-fetch-with-cli: Set GIT_DIR for bare repository compatibility (#14860)
When using `net.git-fetch-with-cli = true` , Cargo fails to clone the git repository into the cache because `safe.bareRepository` defaults to `explicit`. This results in an error stating that a bare repository cannot be used. This patch sets the `GIT_DIR` environment variable to the correct repository path instead of removing it. This ensures that Git uses the correct repository directory and avoids the "cannot use bare repository" error. Fixes #14758
2 parents 8ba3ec2 + b38d06d commit 7aa570a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/cargo/sources/git/utils.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,8 @@ fn fetch_with_cli(
11011101
.args(refspecs)
11021102
// If cargo is run by git (for example, the `exec` command in `git
11031103
// rebase`), the GIT_DIR is set by git and will point to the wrong
1104-
// location (this takes precedence over the cwd). Make sure this is
1105-
// unset so git will look at cwd for the repo.
1106-
.env_remove("GIT_DIR")
1104+
// location. This makes sure GIT_DIR is always the repository path.
1105+
.env("GIT_DIR", repo.path())
11071106
// The reset of these may not be necessary, but I'm including them
11081107
// just to be extra paranoid and avoid any issues.
11091108
.env_remove("GIT_WORK_TREE")

0 commit comments

Comments
 (0)