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

buggy behavior for '--exclude dir/sub' #865

Open
LeGEC opened this issue Oct 14, 2021 · 5 comments
Open

buggy behavior for '--exclude dir/sub' #865

LeGEC opened this issue Oct 14, 2021 · 5 comments
Labels

Comments

@LeGEC
Copy link

LeGEC commented Oct 14, 2021

Describe the bug you encountered:

With the following setup :

$ fd -tf .
dir1/dir1/sub/file
dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file

can be created by running :

	mkdir -p dir1/sub
	mkdir -p dir1/dir1/sub
	mkdir -p dir2/sub
	mkdir -p dir2/dir1/sub
	touch dir1/sub/file
	touch dir1/dir1/sub/file
	touch dir2/sub/file
	touch dir2/dir1/sub/file

using --exclude dir1/sub :

  • searching in '.' applies the exclude pattern as expected
$ fd -tf --exclude dir1/sub . .
dir1/dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file

but searching in dir1 dir2 applies the exclude pattern in an odd way :

$ fd -tf --exclude dir1/sub . dir1 dir2
dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file

Describe what you expected to happen:

I would have expected an output similar to when searching in . :

$ fd -tf --exclude dir1/sub . dir1 dir2
dir1/dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file

What version of fd are you using?

$ fd --version
fd 7.5.0

Which operating system / distribution are you on?

$ uname -srm
Linux 5.11.0-37-generic x86_64
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

extra notes

using a --ignore-file with content dir1/sub works as expected in both cases.


Here is a bash script that reproduces the issue :
issue.txt

it creates an issue/ directory next to the script, and cd into that directory :

$ bash issue.txt 
# with the following setup :
$ fd -tf .
dir1/dir1/sub/file
dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file
ignore.txt

# and the following ignore file :
$ cat ignore.txt
dir1/sub

# using --ignore-file :
#  * searching in '.' works as expected :
$ fd -tf --ignore-file ignore.txt . .
dir1/dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file
ignore.txt

#  * searching in 'dir1 dir2' works as expected :
$ fd -tf --ignore-file ignore.txt . dir1 dir2
dir1/dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file

# using --exclude dir1/sub :
#  * searching in '.' works as expected
$ fd -tf --exclude dir1/sub . .
dir1/dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file
ignore.txt

# Issue : searching in 'dir1 dir2' doesn't work as expected (as I expect, at least)
#   dir1/sub       is *not* excluded
#   dir1/dir1/sub  *is* excluded   (as if the pattern was applied one level to low)
#
# (note that dir2/dir1/sub is still present in the output, which makes for an awkward
#  description of how the --exclude rule is applied)
$ fd -tf --exclude dir1/sub . dir1 dir2
dir1/sub/file
dir2/dir1/sub/file
dir2/sub/file
@LeGEC LeGEC added the bug label Oct 14, 2021
@LeGEC LeGEC changed the title --exclude dir/sub does not behave as if the pattern was provided through a --ignore-file buggy behavior for '--exclude dir/sub' Oct 14, 2021
@AP2008
Copy link

AP2008 commented Oct 21, 2021

--exclude seems to exclude dir1/sub relative to dir1. So, it excludes dir1/dir1/sub.

@tmccombs
Copy link
Collaborator

Ah, I think this might be because of BurntSushi/ripgrep#278 (see also BurntSushi/ripgrep#829). It's a bug in the ignore crate that fd uses.

@AP2008
Copy link

AP2008 commented Oct 21, 2021

Has it been fixed in ripgrep or should the issue be created in the ignore crate ?

@tavianator
Copy link
Collaborator

Those issues are already reported against the repo that contains the ignore crate.

@tmccombs
Copy link
Collaborator

Yes, the ignore crate is in the ripgrep repo.

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

No branches or pull requests

4 participants