Skip to content

cargo publish: false-positive uncommitted error for .gitignored files when package.include is specified #16872

@unclepomedev

Description

@unclepomedev

Problem

Description

When package.include is specified in Cargo.toml, cargo publish incorrectly reports files inside .gitignored directories as uncommitted changes.

Expected behavior

Files inside .gitignored directories should not be reported as uncommitted changes.

Steps

From 3185f58

#[cargo_test]
fn include_does_not_pick_up_gitignored_files() {
    // Ensures `include` directives do not traverse into `.gitignore`d directories.
    let (p, _repo) = git::new_repo("foo", |p| {
        p.file(
            "Cargo.toml",
            r#"
                [package]
                name = "foo"
                version = "0.1.0"
                edition = "2024"
                description = "foo"
                license = "MIT"
                documentation = "foo"
                include = ["src/**/*", "Cargo.toml", "LICENSE"]
            "#,
        )
        .file("src/lib.rs", "")
        .file("LICENSE", "license text")
        .file(".gitignore", ".venv/")
    });

    p.change_file(".venv/some-package/LICENSE", "other license");

    // TODO: not expected behavior
    p.cargo("package --list")
        .with_status(101)
        .with_stderr_data(str![[r#"
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:

.venv/some-package/LICENSE

to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag

"#]])
        .with_stdout_data(str![[r#"
"#]])
        .run();
}

Possible Solution(s)

Part of #16864

Notes

No response

Version


Metadata

Metadata

Assignees

No one assigned

    Labels

    A-vcsArea: general VCS issuesC-bugCategory: bugCommand-packageS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions