Description
Problem
cargo package --list
behavior is inconsistent:
- If
.git
is present, then it contains files starting with.
(i.e. hidden files) - If
.git
is not present, then it doesn't contain hidden files
Steps
cargo new hello
cd hello
touch .emptyfile
optional step to show that even hidden files unrelated to git are ignoredgit add . && git commit -m "init"
cargo package --list
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
.cargo_vcs_info.json
.emptyfile
.gitignore
Cargo.lock
Cargo.toml
Cargo.toml.orig
src/main.rs
As you can see, hidden files are present in the output. Now let's remove the git directory.
rm -rf .git
cargo package --list
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
Cargo.lock
Cargo.toml
Cargo.toml.orig
src/main.rs
I would expect the output of the two commands to be the same. Why do we ignore hidden files if .git
is not present? It is confusing.
Possible Solution(s)
Always include hidden files, even if .git
is not present. I.e. don't differentiate between the two cases (.git present and not present): the behavior should be the same.
Notes
I care about this because, for release-plz, I need to compare the git repository with the crate downloaded from the cargo registry, which doesn't contain the .git
directory. I use cargo package --list
to compare if the two versions of the crate are the same.
As a workaround I'm thinking of running git init && git add . && git commit "init"
in the crate downloaded from the registry, so that the outcome of cargo package --list
is the same.
Version
$ cargo version --verbose
cargo 1.77.1 (e52e36006 2024-03-26)
release: 1.77.1
commit-hash: e52e360061cacbbeac79f7f1215a7a90b6f08442
commit-date: 2024-03-26
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.4.0 (sys:0.4.70+curl-8.5.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Mac OS 14.4.1 [64-bit]