cargo: Cargo package says the repo is dirty, but the files are gitignored

Problem

I have a folder called “extra” that is in my .gitignore. git status confirms it

Screenshot 2023-06-21 at 8 24 38 AM

Cargo package says the repo is dirty, but those files are gitignored.

Screenshot 2023-06-21 at 8 25 20 AM

Note: In my Cargo.toml I am adding this extra folder to the include field, because i want this folder present in the package (but not in git).

Steps

  1. Add a folder with some data to the .gitignore
  2. Include that folder in the cargo package using the include field in the Cargo.toml

Possible Solution(s)

No response

Notes

Normally I worked around the bug with “–allow-dirty”, but now that i’ve switched to cargo release to publish my workspace, I cannot (it doesn’t support that flag)

Version

cargo version --verbose
cargo 1.70.0 (ec8a8a0ca 2023-04-25)
release: 1.70.0
commit-hash: ec8a8a0cabb0e0cadef58902470f6c7ee7868bdc
commit-date: 2023-04-25
host: aarch64-apple-darwin
libgit2: 1.6.3 (sys:0.17.0 vendored)
libcurl: 7.87.0 (sys:0.4.61+curl-8.0.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.3.0 [64-bit]

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

I tried that out, but it didn’t fix the problem. From reading the Cargo book, it seems that once include is specified, .gitignore is no longer relevant.

The behaviour of cargo publish here is desired, even though it might lack refinement for this case: a file is ignored by git and not tracked by git yet - in this case it could probably just be added to the package anyway. Maybe there is a test for that as well and I didn’t see it. Maybe this is something that could be improved when porting this area over to gitoxide, then I should have a better understanding of the tests as well and how it should work in detail.

Speaking only for cargo-smart-release, it doesn’t try to re-implement any ignore logic but relies completely on cargo package - doing a git status check is merely for convenience, and for that it only relies on git itself without extra logic so I think it’s fine in this case.

I figured out the issue. My Cargo.toml had the line include = ["src/**/*", "LICENSE", "README.md"]. The .direnv directory contains files called LICENSE and README.md, which are the uncommitted files cargo was complaining about. Prefixing those file names with a / in Cargo.toml makes cargo happy.

No, cargo package --list still complains with either variation.