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

[BUG] Including hidden files also includes (git)ignored files if the .gitignore is in the parent directory #1461

Closed
1 task done
taeruh opened this issue Dec 27, 2023 · 4 comments · Fixed by #1521
Closed
1 task done
Labels

Comments

@taeruh
Copy link

taeruh commented Dec 27, 2023

Checks

  • I have read the troubleshooting section and still think this is a bug.

Describe the bug you encountered:

Assume we have the following directory structure:

.
├── .abc
├── .gitignore
└── sub_directory
   └── .abc

where

cat .gitignore
.abc

Using fd in the sup_directory with --hidden, I get

fd --hidden
.abc

The .abc file is shown, although it should have been ignored.

Describe what you expected to happen:

Do not show the .abc file.

Note that this only happens in the sup_directory. Using fd --hidden in the root directory shows the expected output.

Possible Fix:

diff --git a/src/cli.rs b/src/cli.rs
index 0007a31..3a7081f 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -643,7 +643,7 @@ impl Opts {
         } else if !self.search_path.is_empty() {
             &self.search_path
         } else {
-            let current_directory = Path::new(".");
+            let current_directory = Path::new("./");
             ensure_current_directory_exists(current_directory)?;
             return Ok(vec![self.normalize_path(current_directory)]);
         };

All tests pass in the github workflows with this change.

The bug is not really caused by something fd is doing but rather by what the "Walker" in the ignore dependency is doing. A simple loop over WalkBuilder::new(path).hidden(false).build() with path = "." and path = "./" leads to the same wrong and correct results, respectively. Maybe one could report it as a bug there? I'm rather confused by this behavior though.

Anyways, the diff above should fix it in fd, I think (could open a PR if you want).

What version of fd are you using?

fd 9.0.0

Which operating system / distribution are you on?

Linux 6.1.69-1-lts x86_64
@taeruh taeruh added the bug label Dec 27, 2023
@taeruh taeruh changed the title Including hidden files also includes (git)ignored files if the .gitignore is in the parent directory[BUG] [BUG] Including hidden files also includes (git)ignored files if the .gitignore is in the parent directory Dec 27, 2023
@tavianator
Copy link
Collaborator

This definitely seems like a bug in the ignore crate. You should have a .git folder in your reproducer, but even with that it fails:

tavianator@graphene $ tree -a .
.
├── .abc
├── .git
├── .gitignore
└── sub_directory
    └── .abc

2 directories, 4 files
tavianator@graphene $ cat .gitignore
.abc
tavianator@graphene $ cd sub_directory
tavianator@graphene $ fd --hidden
.abc
tavianator@graphene $ fd --hidden --search-path ./
tavianator@graphene $ rg --hidden --files .
./.abc
tavianator@graphene $ rg --hidden --files ./
tavianator@graphene $ 

Since rg by itself can reproduce the bug, it should be reported to https://github.com/BurntSushi/ripgrep (unless there's already a duplicate, but I didn't find one quickly).

@tmccombs
Copy link
Collaborator

This seems somewhat similar to BurntSushi/ripgrep#829.

@taeruh
Copy link
Author

taeruh commented Jan 11, 2024

Sorry for not responding earlier; I wanted to dig a little bit into it and hadn't had the time to do that before.

The problems might be similar, but I don't think they are directly related. I think I tracked down the problem for the hidden files in the ignore crate, and made a PR there (BurntlSushi/ripgrep#2711).

In the meantime, until it gets fixed in ripgrep, one could apply the fix I proposed above?

@tmccombs
Copy link
Collaborator

That seems reasonable as long as it doesn't break anything else

tmccombs added a commit to tmccombs/fd that referenced this issue Mar 14, 2024
tmccombs added a commit to tmccombs/fd that referenced this issue Mar 14, 2024
sharkdp pushed a commit that referenced this issue Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants