cargo: cargo-package: list of dirty files contains ignored files

Problem When running “cargo package” it complains about some files containing uncommited change, even though they’re ignored by my .gitignore rules.

This seems to only happen when the file is in a directory that contains a mix of ignored and non-ignored files, but no tracked files at all.

$ git status
On branch master
nothing to commit, working tree clean

$ mkdir new_dir
$ touch new_dir/file
$ touch new_dir/.file.swp

$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        new_dir/

nothing added to commit but untracked files present (use "git add" to track)

$ git status new_dir/
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        new_dir/file

nothing added to commit but untracked files present (use "git add" to track)

$ cargo package
error: 2 files in the working directory contain changes that were not yet committed into git:

new_dir/.file.swp
new_dir/file

I expect to only see the entry for new_dir/file there, not new_dir/.file.swp.

Notes

Output of cargo version:

$ cargo --version
cargo 1.44.1 (88ba85757 2020-06-11)

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

As an attempt I added .DS_Store to .gitignore in the problematic package but it makes no difference.

I was about to say that maybe it’s related to the way the .gitignore rule is specified, for instance by (more) global git configuration)…

[core]
        excludesFile = ~/.gitignore

…but re-reading this means that it can’t be the case.

However, I believe that once the next stage of #11813 (gitoxide support) is rolled out, the issue should disappear and I will be sure to try to verify it truly is fixed then. The reproducer mentioned in the comment right above does not reproduce for me by the way.

I am really sorry to hear that and per my previous comment still puzzled how that happens. My hope would be that the ignore crate can be replaced with gitoxide which I’d expect fixes any issues regarding .gitignore rules, if there are any in the first place.

Similar case here, I believe. On macOS, packaging fails for one of my packages because of verification

error: failed to verify package tarball

Caused by:
  Source directory was modified by build.rs during cargo publish. Build scripts should not modify anything outside of OUT_DIR.
  Added: /Users/jost/Desktop/holochain/holochain-client-rust/target/package/holochain_client-0.4.5-rc.0/.DS_Store

  To proceed despite this, pass the `--no-verify` flag.

I have another package on my system which I could package and publish without such issues. Both contain a .DS_Store file in the root dir. None has it in .gitignore.

As an attempt I added .DS_Store to .gitignore in the problematic package but it makes no difference.

This reproduces the issue on my system:

  • git clone git@github.com:holochain/holochain-client-rust.git cargo-test
  • cd cargo-test
  • cargo package

I am experiencing a possible variant of this, but even if it’s not it’s probably worth piggybacking on this issue to keep it simple.

First of all, I believe this will do my best to assure this gets fixed in the gitoxide implementation.

Now for the problem I am seeing:

# trying to publish `gix-index`
error: 2 files in the working directory contain changes that were not yet committed into git:

src/.DS_Store
src/tbd/.DS_Store

src/tbd/ is untracked and won’t show up in git status as its content, .DS_Store is ignored. src/.DS_Store has more files but all .DS_Store files are ignored.

We can validate this with gix:

gix exclude query gix-index/src/.DS_Store
/Users/byron/.gitignore:4:.DS_Store     gix-index/src/.DS_Store

Even though it didn’t reproduce this time, I also ran into problems with files that couldn’t be packed into the crate due to (intentionally broken) symlinks, even though these are in folders that git-ignored as well.

CC @weihanglo