sharkdp / fd

A simple, fast and user-friendly alternative to 'find'
Apache License 2.0
33.32k stars 795 forks source link

Bug parsing .gitignore #37

Closed suy closed 7 years ago

suy commented 7 years ago

Hi! I'm not entirely sure, but I think I've experienced a bug parsing a git ignore file. I did (with 1.1):

$ cd /tmp/
$ git clone --depth 1 http://code.qt.io/git/qt/qtbase
Cloning into 'qtbase'...
remote: Counting objects: 22136, done.
remote: Compressing objects: 100% (16582/16582), done.
remote: Total 22136 (delta 5296), reused 16146 (delta 3446)
Receiving objects: 100% (22136/22136), 55.12 MiB | 2.70 MiB/s, done.
Resolving deltas: 100% (5296/5296), done.
$ cd qtbase/examples/
$ fd regular
widgets/doc/images/regularexpression-example.png
widgets/doc/src/regularexpression.qdoc
$ fd --no-ignore regular
widgets/tools/regularexpression
widgets/tools/regularexpression/regularexpressiondialog.h
widgets/tools/regularexpression/regularexpression.qrc
widgets/tools/regularexpression/regularexpression.pro
widgets/tools/regularexpression/regularexpressiondialog.cpp
widgets/doc/images/regularexpression-example.png
widgets/doc/src/regularexpression.qdoc

The .gitignore file of that repository may be a bit complex since, if I understand it properly, it uses a glob to add some files that later on are removed with a negative glob. I'm not entirely sure of the rules for it, but to me that is a bug in fd, since the files shown with --no-ignore are not ignored by git.

Thank you!

BurntSushi commented 7 years ago

Your .gitignore contains the rule examples/*/*/*, which in turn causes any and all directories like examples/widgets/tools/regularexpression to be ignored. Namely, they are never descended into.

sharkdp commented 7 years ago

Yes, there is also no ! pattern that overwrites this, as far as I can see. Those files (like widgets/tools/regularexpression/regularexpressiondialog.cpp) are still there because they have been git add-ed explicitly, but the .gitignore pattern matches. If you add a file like widgets/tools/regularexpression/regularexpressiondialog2.cpp, it is captured by the .gitignore file:

> git check-ignore -v widgets/tools/regularexpression/*
.gitignore:4:examples/*/*/* widgets/tools/regularexpression/regularexpressiondialog2.cpp
suy commented 7 years ago

I see, I was testing this now, and it's true, that gitignore rule is not appropiate. I'll see if I can fix the rule.

Thank you (specially for the mindblowingly fast response), and sorry for the trouble.