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

--ignore-file and subdirs #374

Open
Tracked by #695
mwgkgk opened this issue Dec 27, 2018 · 3 comments
Open
Tracked by #695

--ignore-file and subdirs #374

mwgkgk opened this issue Dec 27, 2018 · 3 comments

Comments

@mwgkgk
Copy link

mwgkgk commented Dec 27, 2018

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.

@sharkdp
Copy link
Owner

sharkdp commented Dec 28, 2018

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.

@mwgkgk
Copy link
Author

mwgkgk commented Dec 29, 2018

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.

@tmccombs
Copy link
Collaborator

This might be related to BurntSushi/ripgrep#278 and BurntSushi/ripgrep#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.

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

No branches or pull requests

3 participants