Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelisting via .gitignore does not handle dot prefix ("!./fname") #1374

Closed
blueyed opened this issue Sep 12, 2019 · 4 comments
Closed

Whitelisting via .gitignore does not handle dot prefix ("!./fname") #1374

blueyed opened this issue Sep 12, 2019 · 4 comments
Labels
gitignore Bugs related to gitignore problems. invalid An issue that is not actually a bug or a feature that already exists.

Comments

@blueyed
Copy link
Contributor

blueyed commented Sep 12, 2019

Given a .gitignore file:

*
!./PKGBUILD

rg will skip the PKGBUILD file:

DEBUG|ignore::walk|ignore/src/walk.rs:1639: ignoring ./PKGBUILD: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("./.gitignore"), original: "", actual: "**/", is_whitelist: false, is_only_dir: false })))

This appears to be due to the leading dot there.
Git handles this as expected.

Removing the dot (using !/PKGBUILD) whitelists it then:

DEBUG|ignore::walk|ignore/src/walk.rs:1642: whitelisting ./PKGBUILD: Whitelist(IgnoreMatch(Gitignore(Glob { from: Some("./.gitignore"), original: "!/PKGBUILD", actual: "PKGBUILD", is_whitelist: true, is_only_dir: false })))

What version of ripgrep are you using?

ripgrep 11.0.2

@goto-engineering
Copy link

I just tried this, and my git (2.25.1) seems to show the same behavior:

*
!./test

does not show the test file under git status, whereas

*
!test

does show it.

ripgrep has the exact same behavior.

Even when my .gitignore simply contains:

./test

the test file is NOT being git-ignored. Are we sure that the ./ syntax is supported by gitignore?

@BurntSushi
Copy link
Owner

@blueyed Can you clarify what you meant by "git handles this as expected" in your initial bug report here?

@czarnota
Copy link

czarnota commented Mar 18, 2021

IMHO this is the expected behavior

https://git-scm.com/docs/gitignore

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.

the dot . is a synonym for the parent directory of .gitignore, so in the case of

!./PKGBUILD

"It is not possible to re-include a file if a parent directory (in this case .) of that file is excluded."

Furthermore:

If you specify this .gitignore

*
!foo/bar
$ tree -a
.
├── foo
│   └── bar
└── .gitignore

Then git status also gives you nothing

$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

@BurntSushi
Copy link
Owner

Closing as not a bug. Happy to revisit with more compelling data.

@BurntSushi BurntSushi added invalid An issue that is not actually a bug or a feature that already exists. and removed bug A bug. labels May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gitignore Bugs related to gitignore problems. invalid An issue that is not actually a bug or a feature that already exists.
Projects
None yet
Development

No branches or pull requests

4 participants