Skip to content

net.git-fetch-with-cli fails with "cannot use bare repository" with safe.bareRepository = explicit #14758

@jamuraa

Description

@jamuraa

Problem

When using net.git-fetch-with-cli = true with a sufficiently new git, it fails to clone the git repository into the cache because safe.bareRepository defaults to explicit.

With Cargo.toml:

[package]
name = "git-cli-test"
version = "0.1.0"
edition = "2021"

[dependencies]
cargo = { git = "https://github.com/rust-lang/cargo.git" }

I get

    Updating git repository `https://github.com/rust-lang/cargo.git`
fatal: cannot use bare repository '/usr/local/google/home/jamuraa/.cargo/git/db/cargo-e7ff1db891893a9e' (safe.bareRepository is 'explicit')
error: failed to get `cargo` as a dependency of package `git-cli-test v0.1.0 (/usr/local/google/home/jamuraa/tmp/git-cli-test)`

Caused by:
  failed to load source for dependency `cargo`

Caused by:
  Unable to update https://github.com/rust-lang/cargo.git

Caused by:
  failed to clone into: /usr/local/google/home/jamuraa/.cargo/git/db/cargo-e7ff1db891893a9e

Caused by:
  process didn't exit successfully: `git fetch --force --update-head-ok 'https://github.com/rust-lang/cargo.git' '+HEAD:refs/remotes/origin/HEAD'` (exit status: 128)

This is likely due to the mitigation for https://github.com/justinsteven/advisories/blob/main/2022_git_buried_bare_repos_and_fsmonitor_various_abuses.md

Steps

  1. set net.git-fetch-with-cli = true
  2. Add a git source to Cargo.toml
  3. cargo update (or any other command that will fetch the git repo

Possible Solution(s)

It's likely that adding --git-dir to the git command line will get around this, since cargo is using bare repositories on purpose.

Notes

No response

Version

cargo 1.81.0-nightly (154fdac 2024-07-07)
release: 1.81.0-nightly
commit-hash: 154fdac
commit-date: 2024-07-07
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Debian n/a (rodete) [64-bit]

Metadata

Metadata

Assignees

Labels

A-gitArea: anything dealing with gitC-bugCategory: bugE-easyExperience: EasyS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions