git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How do I qualify paths in the .gitignore file w.r.t. the repo root directory?

From
Sitaram Chamarty <sitaramc@gmail.com>
Date
Feb 25, 2009, 11:17 UTC
Message-ID
<slrngqaa5n.mp1.sitaramc@sitaramc.homelinux.net>
In-Reply-To
<7vab8aap6t.fsf@gitster.siamese.dyndns.org>
On 2009-02-25, Junio C Hamano <gitster@pobox.com> wrote:
> Sitaram Chamarty <sitaramc@gmail.com> writes:
Show 20 quoted lines
>> This is _how_ the patterns match:
>>
>>  - The wildcards (`*` and `?`) do not match slashes, but
>>    otherwise the patterns are normal shell globs as defined
>>    by fnmatch(3) with the FNM_PATHNAME flag set.
>
> I had to read this twice and run "man 3 fnmatch" to clear my head.
>
>  - In normal shell globs, wildcards '*' and '?' do not match slashes;
>
>  - fnmatch(3) with FNM_PATHNAME implements the normal shell globs;
>
>  - wildcards do not match slashes in gitignore either.
>
> Given these three, I am very confused why you say "but otherwise".  I
> would understand it if it were:
>
>     The patterns are treated as normal shell globs defined by fnmatch(3) with
>     FNM_PATHNAME; in other words, the wildcards (`*` and `?`) do not match
>     slashes.
I'll use that.

This confusing statement existed in the previous (shorter) version also. My fault; I use [[ path == patt ]] far more often than plain globs so I had a thinko. (Perversely, that one does *not* use FNM_PATHNAME... go figure!)

Show 12 quoted lines
>>  - An optional prefix '!' negates the pattern; any matching
>>    file excluded by a previous pattern will become included
>>    again.  If a negated pattern matches, this will override
>>    lower precedence patterns sources.
>
> '!' is not part of _how_ the patterns match.  It is _what happens_ when a
> pattern marked as such matches (meaning, the syntax for a line in
> gitignore file is "an optional '!' followed by a pattern").
>
>     An optional prefix '!' is not a part of the pattern and it does not
>     affect the match.  When a path matches such a pattern, instead of
>     being ignored, it is unignored.

I can use this. Can we keep it in the same section, despite being technically not a '_how_'? It fits the other sections even less, and the sectioning is the main thing in all this.

Show 13 quoted lines
> It would be good to clarify that '!' is not part of the pattern, as I'd
> like to take J6t's patch that says gitattributes uses the same pattern as
> gitignore uses.
>
>> This is _what_ the patterns match:
>>
>>  - If the pattern ends with a slash, it matches only
>>    directories (and their contents), otherwise it matches
>>    regular files and symlinks also.
>
> Do we want "(and their contents)" here?  Once a directory is ignored like
> this, none of its contents, including .gitignore file in it, is examined
> because we do not even descend into it.

Do we not want to specify that we don't descend? The original text does say '...will match a directory foo and paths underneath it'.

Show 10 quoted lines
>> This is _where_ the patterns match (a trailing slash is
>> ignored for these rules):
>>
>>  - If there is a slash at the start or within the pattern,
>>    it matches paths relative to the .gitignore file in which
>>    the pattern is found, or to the root of the working tree
>>    if the pattern is from one of the other pattern sources
>>    (i.e., `.git/info/exclude`, `core.excludesfile`)
>
> "at the start or within but not at the end of the pattern"?

Isn't that confusing? 'if there is a slash ... not at the end of the pattern' can easily sound like "there *should not* be a trailing slash", which is quite different from "we don't care if there *is* a trailing slash; it's the *other* slashes that matter here".

And it'll _seem to_ contradict what we say, just above, that a trailing slash is ignored for these rules.

>
>>  - Otherwise, it matches a path at any depth in the tree
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 15 in “How do I qualify paths in the .gitignore file w.r.t. the repo root directory?”
  1. Brent GoodrickFeb 24, 2009
  2. Junio C HamanoFeb 24, 2009
  3. Sitaram ChamartyFeb 24, 2009
  4. Junio C HamanoFeb 24, 2009
  5. Sitaram ChamartyFeb 24, 2009
  6. Sitaram ChamartyFeb 25, 2009
  7. Junio C HamanoFeb 25, 2009
  8. Sitaram ChamartyFeb 25, 2009
  9. Junio C HamanoFeb 25, 2009
  10. Björn SteinbrinkFeb 26, 2009
  11. Sitaram ChamartyFeb 26, 2009
  12. Sitaram ChamartyFeb 26, 2009
  13. Junio C HamanoFeb 26, 2009
  14. Brent GoodrickFeb 25, 2009
  15. Sitaram ChamartyFeb 25, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.