fix: false-positive uncommitted changes for gitignored directories#16864
fix: false-positive uncommitted changes for gitignored directories#16864unclepomedev wants to merge 2 commits intorust-lang:masterfrom
Conversation
|
r? @epage rustbot has assigned @epage. Use Why was this reviewer chosen?The reviewer was selected based on:
|
2f9c9d6 to
80f8958
Compare
|
FYI our contrib process encourages having tests in a commit before the fix, with every commit passing tests, see https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request. I've written up more on this at https://epage.github.io/dev/pr-style/#c-test |
|
Note that #16547 was never labeled |
|
@epage |
|
Also, apologies for overlooking your earlier comment about the contribution process. |
This adds tests to reproduce the issue where `cargo publish` falsely flags `.gitignored` directories (like `.venv` or nested repositories) as uncommitted changes when the `include` option is used. The tests currently expect the erroneous behavior to establish a baseline before applying the actual fix.
When the `include` field is specified in `Cargo.toml`, Cargo's file listing logic previously ignored `.gitignore` rules for directories and traversed into nested git repositories. This caused `cargo package` to report uncommitted changes for files that were not intended to be part of the package. This change ensures that: - `.gitignore` is respected for directory traversal even when the `include` option is used. - Nested git repositories are explicitly skipped during file discovery. Fixes rust-lang#16547
80f8958 to
65c8fc4
Compare
| documentation = "foo" | ||
| homepage = "foo" | ||
| repository = "foo" | ||
| include = ["src/**/*", "tests/**/*"] |
There was a problem hiding this comment.
Simply copying the test from the issue would result in false-negative (the test would pass even without modifying the code), so added an include statement, which is the trigger for the error.
(Without include, Cargo uses the standard ignore logic and the bug doesn't trigger.)
There was a problem hiding this comment.
Doesn't the reproduction is still unclear? Should we discuss in the issue first to be aligned with the issue reporter? The two tests here might be two different issues.
|
Updated the PR to follow the C-TEST guidelines. The changes are split into:
As commented, I found a flaw in the original reproduction. |
There was a problem hiding this comment.
The two reproducible test seem different than each others. And the fix include also ignoring .git and all files under a gitignore'd directory when package.include is specified.
These cases and behavior changes seem to be slightly different and should be discussed and clarified separately in the original issue or a new issue for new bug report.
| // Create a nested git repository in tests/fixtures/ that is gitignored | ||
| // This simulates test fixtures that are git repositories (like gix-dir test fixtures) | ||
| let repo_base = main_repo.root().join( | ||
| "tests/fixtures/generated-do-not-edit/many/613585535-unix/slash-in-root-and-negated/", |
There was a problem hiding this comment.
We probably want toavoid creating such a long path. It might exceed path length limit in some operating systems.
| documentation = "foo" | ||
| homepage = "foo" | ||
| repository = "foo" | ||
| include = ["src/**/*", "tests/**/*"] |
There was a problem hiding this comment.
Doesn't the reproduction is still unclear? Should we discuss in the issue first to be aligned with the issue reporter? The two tests here might be two different issues.
| return false; | ||
| } | ||
|
|
||
| // Skip nested git repositories (see rust-lang/cargo#16547). |
There was a problem hiding this comment.
This is also different than ust-lang/cargo#16547 that unclear to me why we want to ignore when not using include (I knew you added an include).
| if let Some(ref gitignore) = gitignore_for_include { | ||
| if gitignore | ||
| .matched_path_or_any_parents(relative_path, is_dir) | ||
| .is_ignore() | ||
| && !ignore_include | ||
| .matched_path_or_any_parents(relative_path, is_dir) | ||
| .is_ignore() | ||
| { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
This a wrong fix, or at least a significant behavior-breaking change that we should consider more cases. For example, if a directory is gitignore'd but user request to package.include a specific file inside it, after this change the file won't be included.
|
Reminder, once the PR becomes ready for a review, use |
|
Thank you for the thorough review.
|
|
I've confirmed with the issue reporter that we're facing the same issue: a false-positive uncommitted error occurs during
Would that be okay, or would you prefer them as separate issues? |
|
Thanks for the investigation! They may have different compatibility guarantee, so separate issues sounds better to manage the discussion. |
Fixes #16547
(as patch before gix-dir)
What does this PR try to resolve?
Fixes false-positive 'uncommitted changes' errors during cargo publish caused by
.gitignored directories (e.g., .venv) in workspace setups.How to test and review this PR?
include = ...line that triggers this bug.