broot icon indicating copy to clipboard operation
broot copied to clipboard

Files in directories with whitelist-style .gitignore are hidden

Open mmaulwurff opened this issue 2 years ago • 4 comments

Consider the .gitignore:

# Ignore everything, but not directories:

*
!**/

# Except the following file types:

!.gitignore

!**.txt
!**.md

Broot doesn't show any file in the directory with such .gitignore:

ls -a
.  ..  credits.txt  .git  .gitignore  Readme.md

BROOT_LOG=debug br
/home/allkromm/src/bugs/broot-gitignore

mv .gitignore ..

BROOT_LOG=debug br
/home/allkromm/src/bugs/broot-gitignore
 ├──broot.log 
 ├──credits.txt 
 └──Readme.md 

Steps to reproduce the behavior:

  1. Open a directory with git repository and gitignore like described above (minimal example attached);
  2. Launch Broot;
  3. Type pt;

Expected behavior: credits.txt and Readme.md files are displayed. Actual behavior: they are not displayed.

Files are displayed if .gitignore file is removed from the directory, or if gi flag is no.

  • broot version: broot 1.6.3
  • OS: Debian
  • Version: 11.0

broot.log broot-gitignore.zip

There is a mention of whitelist-style .gitignore files here: https://github.com/Canop/broot/issues/35#issuecomment-753346679

mmaulwurff avatar Sep 06 '21 15:09 mmaulwurff

What isn't currently supported by broot's implementation of gitignore is a family of patterns like **.txt or !**.txt. It must be noted that those patterns shouldn't be present in a .gitignore as they don't make sense and are confusing, being equivalent to *.txt and !*.txt (reference).

The fact is git doesn't complain and silently accepts any number of consecutive stars in this context. Broot should idealy do the same. It's not the case because the "glob" crate I'm using rejects those patterns as invalid ("recursive wildcards must form a single path component"), which is probably the right behavior usually.

I'm not sure of what I'll do. I might solve the problem by switching to the globset crate if it has the same performance (which is probable). In the meantime I suggest you fix your .gitignore files.

Canop avatar Oct 01 '21 08:10 Canop

You are right. Thanks for the explanation!

I guess I have a bunch of .gitignore files to fix.

mmaulwurff avatar Oct 01 '21 15:10 mmaulwurff

Don't close the issue: I'm still trying to have the same behavior than git (I'm trying the globset crate at the moment, must check for all possible regressions...)

Canop avatar Oct 01 '21 15:10 Canop

In fact I can't use the globset crate. I get a huge perf penalty when using it.

Canop avatar Oct 01 '21 16:10 Canop