Giter Club home page Giter Club logo

Comments (8)

BurntSushi avatar BurntSushi commented on June 11, 2024

This is correct behavior. From the man page:

       The precedence of ignore rules is as follows, with later items overriding earlier items:

       •  Files given by --ignore-file.

       •  Global gitignore rules, e.g., from $HOME/.config/git/ignore.

       •  Local rules from .git/info/exclude.

       •  Rules from .gitignore.

       •  Rules from .ignore.

       •  Rules from .rgignore.

In other words, --ignore-file has the lowest precedence and is overruled by your .gitignore. The whitelist rule in .ignore works because .ignore specifically has higher precedence.

The docs for --ignore-file appear misleading or perhaps even wrong:

       --ignore-file=PATH
           Specifies a path to one or more gitignore formatted rules files.  These patterns are applied after the  patterns  found  in
           .gitignore,  .rgignore  and  .ignore  are applied and are matched relative to the current working directory. Multiple addi‐
           tional ignore files can be specified by using this flag repeatedly. When specifying multiple ignore  files,  earlier  files
           have lower precedence than later files.

           If  you  are looking for a way to include or exclude files and directories directly on the command line, then use -g/--glob
           instead.

This should be rephrased to say that they have lower precedence than rules from other ignore files.

from ripgrep.

noirbizarre avatar noirbizarre commented on June 11, 2024

OK, make sense.

Is there a way to provide a global override file so ?

Main use case: I have some personal files which I ignore globally using a global git ignore (let's say .envrc or .mise.toml) that I know I always want to find in search results (this is why I have !.mise.toml and !.envrc in my ~/.config/search.ignore)

Ideally, to make everyone happy, there should be both:

  • a --ignore-file-override parameter or equivalent to be able to specify on-demand
  • a $RG_IGNORE_FILE_OVERRIDE environment variable to be able to specify once globally or by environment

If there is no such possibility, would you accept a pull-request adding it (it might take time, I'm no rust expert, still learning) ?

from ripgrep.

BurntSushi avatar BurntSushi commented on June 11, 2024

Sure, you could create a /.rgignore since any .rgignore file has precedence over all other .gitignore files, for example. ripgrep will ascend parent directories to find ignore files.

Otherwise, no, I'm not accepting any major changes to how ignore rules work in ripgrep right now. Not until the system has been re-thought and probably redesigned.

from ripgrep.

noirbizarre avatar noirbizarre commented on June 11, 2024

Too bad, one .ignore or .rgignore by repository doesn't really scale because I have a huge amount of repositories to handle (I started with that and then submitted the issue when I realized the amount of file I have to create, a lifetime of projects history, each one having a combination of multiple files or directories I gitignored but need to match using rg).

I'll wait for the redesign. Thanks for the quick and precise answers !

from ripgrep.

BurntSushi avatar BurntSushi commented on June 11, 2024

You don't need to put a .rgignore in each repository. I'm not sure where you got that from. You only need to put it in a shared parent directory. Hence the suggestion to use /.rgignore. That's /, the root of your file system. Not the root of each project directory. Of course, it doesn't have to be in the root of your file system. If all your repos are in ~/clones, then you could put it at ~/clones/.rgignore.

from ripgrep.

noirbizarre avatar noirbizarre commented on June 11, 2024

You only need to put it in a shared parent directory.

Oh, that will do it !! Thanks for the tip, I wasn't aware that parent files are processed ! 🙏🏼
Edit: working just fine, solved my issue !

I'm not sure where you got that from.

Hard to answer. This has been a long journey (not) finding this right info:

The rg --help section about --ignore-file only talks about the current working directory for those files. And this is also the one that made me think there was a bug given it says clearly These patterns are applied after the patterns found in .gitignore...

--ignore-file=PATH
        Specifies a path to one or more gitignore formatted rules files. These
        patterns are applied after the patterns found in .gitignore, .rgignore
        and .ignore are applied and are matched relative to the current working
        directory. Multiple additional ignore files can be specified by using
        this flag repeatedly. When specifying multiple ignore files, earlier
        files have lower precedence than later files.

Then I found the User Guide dedicated section referenced in the README, but it only talks about git specific ignore files (including only globals from core.excludesFile and current dir .ignore that override, no reference to --ignore-file nor to parent files).

So I read comments from all the PRs on the topics trying to find data and one was saying that only the current repository .(rg|git|)ignore files are handled (and that rg is converging toward using .ignore) as well as the "global ignore files" but without details on what it means.

I wasn't even aware that there is a man page, it's not said once in the README, the User guide or the --help (or more precisely I missed it if this is the case).

So clearly a documentation issue and I might submit PR clarifying that between the readme, the help, the user guide and the manpage. Would you accept such pull request ?

from ripgrep.

BurntSushi avatar BurntSushi commented on June 11, 2024

Hard to answer. This has been a long journey (not) finding this right info

Ah yeah, sorry, I was referencing my prior comment where I suggested /.rgignore. :-)

Otherwise I agree that the whole UX around ignore rules is sub-optimal. There are also legitimate bugs with its implementation. So it's all a bit of a mess unfortunately, but mostly works.

from ripgrep.

BurntSushi avatar BurntSushi commented on June 11, 2024

So clearly a documentation issue and I might submit PR clarifying that between the readme, the help, the user guide and the manpage. Would you accept such pull request ?

Yes I'd be happy to try and work with you on that. Thank you!

from ripgrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.