Re: Feature Request: gitignore recursion
- From
Jeff King <peff@peff.net>
- Date
- Oct 10, 2013, 16:22 UTC
- Message-ID
- <20131010162244.GA21489@sigill.intra.peff.net>
- In-Reply-To
- <52565E6A.2020907@gmail.com>
On Thu, Oct 10, 2013 at 09:59:38AM +0200, Karsten Blees wrote:
Show 22 quoted lines
> > On Mon, Oct 07, 2013 at 07:24:11AM -0400, Jeff King wrote: > >> However, one thing I expected to work but didn't is: > >> > >> echo '*' >.gitignore > >> echo '!*' >my_dir/.gitignore > >> > >> That _does_ work for attributes, like: > >> > >> echo '* foo=one' >.gitattributes > >> echo '* foo=two' >my_dir/.gitattributes > >> > >> where the more-specific file takes precedence. It works because we keep > >> an attribute stack, and look from most-specific directory to least. > > Note that this doesn't work either: > > echo '*' >.gitignore > echo '!my_dir/*' >>.gitignore > > The problem isn't that git doesn't read 'my_dir/.gitignore'. Git > simply doesn't recurse into excluded directories, so patterns on > excluded content have no effect.
Good point. To make it work you need to un-ignore the subdir, like:
* !my_dir/
at which point "!my_dir/*" will work. But then so will a child .gitignore in subdir. In fact, I think the only reason that "!my_dir/**" is needed in the first place is that the "*" is too over-reaching; it ignores both the top-level directories _and_ all of the individual files in included directories.
So I think the best solution for the original problem, which is to ignore everything except for a particular directory, is:
# ignore everything at the top-level... /* # ...but specifically include one directory !/my_dir/
and then we do not even need to use "**" matching at all (which was really about overriding the over-reaching "*").
> IMO this behavior is reasonable, as there is no way to check whether a > negative pattern will match within an excluded untracked directory > without scanning the directory.
Right. I was focused on not reading the .gitignore, but not descending into the ignore subdir affects patterns we already know about, too.
Show 7 quoted lines
> --- 8< --- > Subject: [PATCH] gitignore.txt: clarify recursive nature of excluded directories > > Additionally, precedence of negated patterns is exactly as outlined in > the description, we don't need to repeat this. > > Signed-off-by: Karsten Blees <blees@dcon.de>
Yeah, I think your update improves things.
I wonder if it is worth adding the "exclude everything except one directory" case above to the EXAMPLES section, too.
-Peff