threads / discuss / 26850

`*' gitignores and nested ignores

Subject: `*' gitignores and nested ignores

## tl;dr

3 messages between Mar 24, 2011 and Mar 25, 2011.

replies: 2people: 2as markdown or json

Eli Barzilay· Mar 24, 2011, 10:10 UTC · lore

According to the man page, a .gitignore file that is deeper has higher precedence, and a `!' line overrides lower precedence ignores. I tried that, and it works in cases like the last "vmlinux*" example.

But it doesn't work if the lower precedence directory has a "*" pattern. If the last example from the man page is changed to:

               $ cat .gitignore
               *
               $ ls arch/foo/kernel/vm*
               arch/foo/kernel/vmlinux.lds.S
               $ echo ´!/vmlinux*´ >arch/foo/kernel/.gitignore

then -- IIUC -- the second ignore should work the same, but it doesn't. This also happens if the first pattern is "/*".

Is this a bug?

BTW, my use case is to track random stuff in a directory that has lots of junk. I wanted to do this by having a toplevel "/*" ignore and add files explicitly when I want to. But there are some directories that should be tracked, and I was trying to achieve this effect by adding a "!/*" pattern in them. Is there a more convenient (or saner) way of doing this?

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Johannes Sixt· Mar 25, 2011, 08:18 UTC · re: Eli Barzilay · lore

Re: `*' gitignores and nested ignores

Am 3/24/2011 11:10, schrieb Eli Barzilay:
Show 17 quoted lines
> According to the man page, a .gitignore file that is deeper has higher
> precedence, and a `!' line overrides lower precedence ignores.  I
> tried that, and it works in cases like the last "vmlinux*" example.
> 
> But it doesn't work if the lower precedence directory has a "*"
> pattern.  If the last example from the man page is changed to:
> 
>                $ cat .gitignore
>                *
>                $ ls arch/foo/kernel/vm*
>                arch/foo/kernel/vmlinux.lds.S
>                $ echo ´!/vmlinux*´ >arch/foo/kernel/.gitignore
> 
> then -- IIUC -- the second ignore should work the same, but it
> doesn't.  This also happens if the first pattern is "/*".
> 
> Is this a bug?
This has been discussed before, and IMNSHO, this is not a bug:
http://thread.gmane.org/gmane.comp.version-control.git/157190
-- Hannes
Eli Barzilay· Mar 25, 2011, 09:37 UTC · re: Johannes Sixt · lore

Re: `*' gitignores and nested ignores

An hour ago, Johannes Sixt wrote:
Show 14 quoted lines
> Am 3/24/2011 11:10, schrieb Eli Barzilay:
> > According to the man page, a .gitignore file that is deeper has
> > higher precedence, and a `!' line overrides lower precedence
> > ignores.  I tried that, and it works in cases like the last
> > "vmlinux*" example.
> > 
> > But it doesn't work if the lower precedence directory has a "*"
> > pattern.  [...]
> > 
> > Is this a bug?
> 
> This has been discussed before, and IMNSHO, this is not a bug:
> 
> http://thread.gmane.org/gmane.comp.version-control.git/157190
To reply to what you wrote there:
> You should update your expectations to match what you got.

That kind of an answer is a thick hint that something is not documented right. As things stand, I don't see anything in the man page that describes the actual algorithm that is used. I also found a similar weirdness now -- the man page says

  within one level of precedence, the last matching pattern decides
  the outcome
but this is not true for nested files in this case:
  *
  !foo

So some description of what's going on is needed. Perhaps it's exactly what Seth's suggested patch describes.

In any case, it seems possible to do something that works more as expected. As suggested in that thread -- scanning only directories that have committed files would not make things slow, since the files need to be checked anyway. This is not even hard to describe in a man page. It seems like some arbitrariness that buys performance, but its less so than the current situation.

There's also the option of scanning only .gitignore files that are checked in, but that will probably be too confusing when the files are created and/or modified.

Yet another alternative is to say that an ignored .gitignore file is ignored, and making this:

  /*
  !.gitignore
an idiom for doing the slow thing in case you really want it.
-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

← back to recent threads