Fd: --ignore-file and subdirs

Created on 27 Dec 2018  路  3Comments  路  Source: sharkdp/fd

Forward slash is special in .gitignore format, in that a trailing slash is stripped but means to only match directories, and the behavior of shell globs * ? and [] is changed if / is present.

Now to the point: In fd, --ignore-file patterns don't match subdirs. To ignore a dir1/file1.txt,

dir1/file1.txt

doesn't work. To make it work, replace / with * :

dir1*file1.txt

The first pattern does work for fd when placed into a .gitignore.

More fail cases:

dir1/**

Is supposed to match files recursively, does nothing, works in .gitignore.

/dir1

Is supposed to match from the beginning of the pattern (so, sort of not what one would expect?), does nothing, works in .gitignore.

As a sub-case of the above, /* does not work (probably because / changes the behavior); /** and * do.

documentation help wanted upstream-error

Most helpful comment

This might be related to https://github.com/BurntSushi/ripgrep/issues/278 and https://github.com/BurntSushi/ripgrep/issues/829. Which are both bugs caused by the same behaviour in the ignore library, where it uses the current working directory places it shouldn't.

All 3 comments

Thank you for reporting this.

If you add files via --ignore-file, the patterns are always matched relative to the current working directory (we should document this). So your dir1/file1.txt example should work if dir1 is in the current directory.

This behavior is inherited from the ignore crate, which is also used in ripgrep. I think the intention behind this is that there is no "repository root" for these custom ignore files, so using the current working directory seems like a reasonable choice. However, I agree that it is unexpected that dir1/file1.txt does not match another-folder/dir1/file1.txt.

I'm not sure, if there is an easy way to change this, though.

Interesting! The current working directory thing makes it so fd -t f "" repo/ expects the --ignore-file to say repo/dir1/file1.txt. In other words, current working directory means the directory fd was called from, not the target directory passed as an argument.

So the temporary workaround for scripting use would be to cd repo/ && fd -t f "" . instead.

This might be related to https://github.com/BurntSushi/ripgrep/issues/278 and https://github.com/BurntSushi/ripgrep/issues/829. Which are both bugs caused by the same behaviour in the ignore library, where it uses the current working directory places it shouldn't.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sharkdp picture sharkdp  路  3Comments

mathomp4 picture mathomp4  路  3Comments

mrzool picture mrzool  路  4Comments

hungptit picture hungptit  路  3Comments

nishithkhanna picture nishithkhanna  路  4Comments