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

Prioritation of global anti-ignores (includes) for fd. #655

Open
kazie opened this issue Sep 25, 2020 · 10 comments
Open

Prioritation of global anti-ignores (includes) for fd. #655

kazie opened this issue Sep 25, 2020 · 10 comments
Labels

Comments

@kazie
Copy link

kazie commented Sep 25, 2020

What version of fd are you using?

fd 8.1.1

Hello there, I am happy to find that you have the new feature:

Add global fdignore support #575

But I couldn't get it to work, so let me explain my usecase and thought how I could gotten it to work.

Let's imagine I have a personal global file ending that I don't want to be checked into any of my git projects (except when I choose to force it in). Example ending with ~ as emacs backup files or in my personal example below *.bak.

My intention is to enable this file to be found with fd without having to completely ignore all the good ignores. While it still shall be ignored with my global gitingore.


Example granted:
I have a folder with two files, one of which is my *.bak file

kazie@r2m-kazie:~/s/test|HEAD⚡> ls -l
total 0
-rw-r--r-- 1 kazie kazie 0 Sep 25 09:25 file
-rw-r--r-- 1 kazie kazie 0 Sep 25 09:25 file.bak

I have it such that it is ignored by my global gitignore file, which I have set myself to ~/.gitignore.

kazie@r2m-kazie:~> git config --global core.excludesfile
~/.gitignore
kazie@r2m-kazie:~/s/test|HEAD⚡> cat ~/.gitignore
# personal tmp files
*.bak

if I check git status it will correctly not find the *.bak file, as intended.

kazie@r2m-kazie:~/s/test|HEAD⚡> git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	file

nothing added to commit but untracked files present (use "git add" to track)

I thought "I should add an not-ignore in my global fd-ignore file"
Which I hope I did

kazie@r2m-kazie:~/s/test|HEAD⚡> cat ~/.config/fd/ignore
!*.bak

But still I cannot get fd to find the bak file while to still have git ignoring it.

kazie@r2m-kazie:~/s/test|HEAD⚡> fd .
file

My expection and hope was that fd would not have ignored the *.bak file here.


Is this the intended behavior?
Or maybe I have screwed up with my though process?

I read from the issue of #575

From what I can see, priority is fd/ignore < --ignore-files < .gitignore < .ignore < .fdignore
Which would make the global fd/ignore file less prioritized, and I guess that what I actually want is not to ignore things, but to unignore or include.

Maybe the feature is correct and works as intended, and I should request some kind of fd-include file or something that would take on priority?


Maybe this whole question is related to #503?

@kazie kazie added the question label Sep 25, 2020
@sharkdp
Copy link
Owner

sharkdp commented Dec 1, 2020

Thank you for reporting this

@soedirgo Any chance you could take a look at this?

@soedirgo
Copy link
Contributor

soedirgo commented Dec 8, 2020

Sorry for the wait!

Which would make the global fd/ignore file less prioritized, and I guess that what I actually want is not to ignore things, but to unignore or include.

You're exactly right, the reason for the global ignore to have lower priority was because I intended it to be like --ignore-file, which was already there. In your case, what you want is fd --no-ignore-vcs ., so .gitignore files don't take priority.

@kazie
Copy link
Author

kazie commented Dec 16, 2020

Sorry for my late response.
I do understand that I could use --no-ignore-vcs but that seems like a really bad fix to do something like:

alias fd="fd --no-ignore-vcs"

As that would disable the feature of ignoring things in git files and such in its entirety.

  13   │         --no-ignore-vcs
  14   │             Show search results from files and directories that would otherwise be ignored by '.gitignore' files.

And from this, one of the major features I also like would be forced to be disabled - since I like ignoring files with gitignore - just like I want to setup fd to "ignore a specific ignore" from the file and not all of it. Thus the:

!*.bak

in the

  ~/.config/fd/ignore

file.


So I suppose this would be needed to be rewritten to some sort of feature request? Or does my problem, want thing I want to do make any sense? :)

@soedirgo
Copy link
Contributor

Hmm, that makes sense. I think the solution is to use .fdignore, which will get applied in the directory it's in as well as its children. It's not a clean solution either, but it's the only way I can think of to include stuff to override .gitignores.

@jdrouhard
Copy link

Commenting on an almost 2-year-old issue (sorry...), but I'm running into the same issue with 8.4.0, and using a .fdignore alone doesn't actually work:

$ cat .gitignore
build/
$ cat .fdignore
!*.cpp
build/
$ mkdir build
$ touch build/hello.cpp
$ fd --no-ignore-vcs .
$ fd .
$

Seems I am unable to ignore ignores entirely and .fdignore by itself doesn't do the trick.

@tmccombs
Copy link
Collaborator

One possible solution would be to have a separate config file that has a higher priority than any other ignore files.

@tavianator
Copy link
Collaborator

@jdrouhard Did you mean to put !build/ in the .fdignore? That seems to work.

@jdrouhard
Copy link

No, I want to ignore everything in build/ except files ending in .cpp (for this example).

What I'm really trying to do is let fd find files that match a certain pattern inside directories that are otherwise excluded. I have a build directory (ignored in .gitignore) with autogenerated source files and would like to be able to list the generated files inside that directory while excluding everything else. I can make the command as complicated as necessary (even recreating a .fdignore that slightly differs from the .gitignore), but it doesn't seem to be possible at all right now :/

@tmccombs
Copy link
Collaborator

The way gitignore, and by extension fdignore, works is if a directory is ignored, then that directory isn't traversed at all, so it is impossible to unignore anything inside 5hay directory, unless you also unignore the directory itself.

@tavianator
Copy link
Collaborator

@jdrouhard I see. You could do this in .fdignore:

!build/
build/*
!*.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6 participants