Skip to content

fix: do not list hidden files negated in .gitignore without --hidden - #2097

Open
SomSamantray wants to merge 4 commits into
sharkdp:masterfrom
SomSamantray:fix/hidden-files-negated-gitignore
Open

fix: do not list hidden files negated in .gitignore without --hidden#2097
SomSamantray wants to merge 4 commits into
sharkdp:masterfrom
SomSamantray:fix/hidden-files-negated-gitignore

Conversation

@SomSamantray

Copy link
Copy Markdown

Without --hidden, fd now never lists dot-prefixed hidden entries, even when a .gitignore pattern negates them. Previously, a negation such as !.gitignore bypassed the ignore crate's hidden filter and the file was listed; negated hidden directories were traversed as well. Hidden directories are now pruned, so their contents are not searched. With --hidden, behavior is unchanged.

The check is name-based and runs before the --min-depth guard, so the hidden contract holds regardless of depth configuration.

Fixes #1266

One known limitation: on Windows, files hidden via FILE_ATTRIBUTE_HIDDEN whose names lack a leading dot are not covered by the name-based check. The follow-up is tracked separately (see Related).

Related: #2096

Validation: new regression test test_hidden_negated_gitignore fails on master and passes here. It covers self-negated hidden files, negated hidden directories, and --min-depth interplay. Full suite: 157 unit + 109 integration tests pass; cargo fmt and cargo clippy --all-targets --all-features -- -Dwarnings are clean. Manual repro of the issue verified against a local build.

Session-settled decisions carried from planning: no third-party branding on this PR (user-directed); fd contribution guidelines followed (user-directed).

AI disclosure: This PR was produced with the assistance of an AI coding assistant (fix implementation, regression test, changelog entry, and PR scaffolding) and was reviewed by the human author before submission.

@tmccombs tmccombs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior is intentional.

Hidden files are not supposed to be shown unless --hidden is used. Negation in ignore files is intended to negate the ignore mechanism, not force the file to be shown even if it otherwise wouldn't be.

@tmccombs tmccombs Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be checked in

@tmccombs tmccombs closed this Aug 16, 2026
@tmccombs

Copy link
Copy Markdown
Collaborator

Oh, I'm sorry, I misread the description.

However, I still think this needs work.

I'll reopen and submit a needs-work review.

@tmccombs tmccombs reopened this Aug 16, 2026

@tmccombs tmccombs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, I think it would be better if this was fixed in the ignore crate itself, or at least if the ignore create provided an option to do this. See BurntSushi/ripgrep#3514. Although if that is unlikely to happen, or would take to long, I'm fine with something like this.

Secondly, I think we should do this in a way that works for windows as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hidden files are wrongly listed if negated in .gitignore

2 participants