cargo: cargo does not see `Cargo.toml` if `.gitignore` contains `/*`
Problem
If .gitignore is written in the style of “ignore everything except this”, then cargo package --list for some reason does not see anything.
It seems to me that everything was fine on previous versions, I spent an hour investigating, did I miss something?
cargo version: 1.80.1 (376290515 2024-07-16)
git version 2.39.2 (Apple Git-143)
OS: mac
Cargo.toml:
[package]
name = "gitignore-bug"
version = "0.1.0"
edition = "2021"
license = "MIT"
description = "to reproduce bug"
[dependencies]
.gitignore:
/target
/*
!.gitignore
!Cargo.toml
!src
cargo package --list
warning: manifest has no documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
warning: no `Cargo.toml` file found when packaging `gitignore-bug` (note the case of the file name).
.cargo_vcs_info.json
Cargo.lock
Steps
cargo init
echo '\n/*\n\n!.gitignore\n!Cargo.toml\n!src' >> .gitignore
git add . && git commit -m "."
cargo package --list
Possible Solution(s)
No response
Notes
cargo build is working, cargo publish is not working
Version
cargo 1.80.1 (376290515 2024-07-16)
release: 1.80.1
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.7.1 (sys:0.4.72+curl-8.6.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Mac OS 13.6.8 [64-bit]
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (10 by maintainers)
I was also unable to reproduce the issue with
v1.80.1andv1.82.0.My guess is that this
gitoxidecommit is the fix that was first introduced ingixv0.64- maybe older cargo releases with prior versions ofgixsuffer from the issue, i.e. directory traversal would allow to skip the traversal root when everything was excluded, with only includes to go by.I don’t even have a question for @cospectrum as it’s clear by now that we can’t reproduce the issue, which probably means that some global git configuration is affecting this unexpectedly. It’s actually kind of impossible right now to disable this effect without recompiling, unfortunately.
Apologies for getting back to this with such a delay, but there is good news: It looks like the latest
masteralready has a fix.In the example output below,
../testingwas initialized with the reproducer from this issue.The fix is part of
gixv0.64, which comes withgix-dirv0.6.0 that is very likely the crate the contains the actual fix.As a lower boundary, when compiling an older version (
88957a1b7f65b233118dcd4f59df2763043ef9dd ~100), the issue can be reproduced in the test setup used here:Thus, no action is needed unless a backport is desired. Then I’d have to try and port the fix to
gix-dirv0.5.x and Cargo would need another patch release after updating to it.That’s great! Actually, I noticed that previously
cargo initdidn’t initialize a repository in the newly created cargo project as I invoked it from within the Cargo repository.Once that is fixed, I can reproduce the issue.
On it now.