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
Junio C Hamano <gitster@pobox.com>
Date
Feb 25, 2009, 08:36 UTC
Message-ID
<7vab8aap6t.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<slrngq9es5.ik0.sitaramc@sitaramc.homelinux.net>
Sitaram Chamarty <sitaramc@gmail.com> writes:
Show 16 quoted lines
> Please tell me what you think.  If you like it, I'll send in
> this patch.  If you prefer the previous one, I'll send that
> in.
> ...
> The files containing the patterns have the following format:
>
>  - A blank line matches no files, so it can serve as a
>    separator for readability.
>
>  - A line starting with # serves as a comment.
>
> 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.
>  - 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.

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.

Show 5 quoted lines
> 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.

Show 8 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"?
>  - Otherwise, it matches a path at any depth in the tree
Previous: Sitaram ChamartyNext: Sitaram Chamarty
Message 7 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.