Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jamuraa opened this issue Oct 31, 2024 · 3 comments
Labels
A-git Area: anything dealing with git C-bug Category: bug E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@jamuraa
Copy link

jamuraa commented Oct 31, 2024

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]

@jamuraa jamuraa added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Oct 31, 2024
@epage epage added the A-git Area: anything dealing with git label Oct 31, 2024
@ehuss
Copy link
Contributor

ehuss commented Oct 31, 2024

safe.bareRepository defaults to explicit.

Can you say more about how this default is set? I have 2.47.0, and it seems to default to "all" (and that matches the code). Do you maybe have a user or system config that is changing the setting? What does git config --show-origin safe.bareRepository say?

@jamuraa
Copy link
Author

jamuraa commented Oct 31, 2024

Can you say more about how this default is set? I have 2.47.0, and it seems to default to "all" (and that matches the code). Do you maybe have a user or system config that is changing the setting? What does git config --show-origin safe.bareRepository say?

Ah, this is set by my system admin (overriding the default) in /usr/share/git-core/config - but I believe it should be possible to use cargo with cli even when this is set.

That does make this less urgent, but I think it would be good for cargo to work with git from cli even when this is set, and it's probably a good idea to set it using --git-dir or the env variable anyway since cargo is explicitly working with bare repos.

@ehuss ehuss added S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. and removed S-triage Status: This issue is waiting on initial triage. labels Oct 31, 2024
@epage epage changed the title net.git-fetch-with-cli fails with "cannot use bare repository" net.git-fetch-with-cli fails with "cannot use bare repository" with safe.bareRepository = "explicit' Oct 31, 2024
@epage epage changed the title net.git-fetch-with-cli fails with "cannot use bare repository" with safe.bareRepository = "explicit' net.git-fetch-with-cli fails with "cannot use bare repository" with safe.bareRepository = explicit Oct 31, 2024
@weihanglo
Copy link
Member

That does make this less urgent, but I think it would be good for cargo to work with git from cli even when this is set, and it's probably a good idea to set it using --git-dir or the env variable anyway since cargo is explicitly working with bare repos.

$ git fetch --git-dir
error: unknown option `git-dir'

Since --git-dir option on git-fetch doesn't seem to be present, the alternative would be set GIT_DIR to repo.path() here:

.env_remove("GIT_DIR")

@weihanglo weihanglo added E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

No branches or pull requests

4 participants