git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Karsten Blees <karsten.blees@gmail.com>
Cc: pclouds@gmail.com, Git List <git@vger.kernel.org>, alljeep@gmail.com
Subject: Re: Feature Request: gitignore recursion
Date: Thu, 10 Oct 2013 12:22:44 -0400	[thread overview]
Message-ID: <20131010162244.GA21489@sigill.intra.peff.net> (raw)
In-Reply-To: <52565E6A.2020907@gmail.com>

On Thu, Oct 10, 2013 at 09:59:38AM +0200, Karsten Blees wrote:

> > 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.

> --- 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

  reply	other threads:[~2013-10-10 16:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-06 22:23 Feature Request: gitignore recursion AJ
2013-10-07 10:26 ` Duy Nguyen
2013-10-07 11:24   ` Jeff King
2013-10-07 13:41     ` Duy Nguyen
2013-10-10  7:59       ` Karsten Blees
2013-10-10 16:22         ` Jeff King [this message]
2013-10-10  7:59   ` Karsten Blees

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131010162244.GA21489@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=alljeep@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karsten.blees@gmail.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).