Skip to content

Directory entries in .gitignore are not processed in the same way as in Git #3236

@Cerber-Ursi

Description

@Cerber-Ursi

Please tick this box to confirm you have reviewed the above.

  • I have a different issue.

What version of ripgrep are you using?

Not a ripgrep itself, but ignore v0.4.25; reproduced at current master branch at the moment of writing.

How did you install ripgrep?

Just using ignore from crates.io.

What operating system are you using ripgrep on?

Arch, rolling release

Describe your bug.

When .gitignore file contains a literal directory reference, ignore still includes contents of that directory. This is in contradiction with git itself, which ignores this directory.

What are the steps to reproduce the behavior?

Reproduces with the following test in ignore:

#[test]
fn gitignore_directory() {
    let td = tmpdir();
    mkdirp(td.path().join("a"));
    wfile(td.path().join(".gitignore"), "/a");
    wfile(td.path().join("a/foo"), "");

    let root = td.path();
    assert_paths(&root, &WalkBuilder::new(&root), &[]);
}

Real-life case: repository with a single Rust project, where .gitignore file is as following:

/target

What is the actual behavior?

Files in the .gitignored directory are included in a walk.

What is the expected behavior?

Files in the .gitignored directory are ignored, as they do when using git.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions