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

Re: Git attributes ignored for root directory

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 5, 2011, 17:38 UTC
Message-ID
<7vd3eb8hkb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4E8C481A.1070808@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 9 quoted lines
> Indeed, your use case is broken by
>
> f5114a40c0d0276ce6ff215a3dc51eb19da5b420
>
> In fact the support for gitattributes using patterns involving "." was
> pretty spotty in v1.7.6 too.  For example,
> ...
> I conclude that this functionality was never really defined correctly,
> and you were pretty lucky that your case worked at all :-)

The attribute patterns (or exclude patterns for that matter) were never designed to name "the current directory". The way to name "everything *in* this directory" has always been to say "*" (the "* text=auto" example in the documentation says it shows how to set the attribute "for all files"). Admittedly the pattern may miss ".*" files.

I have to agree that things like "./" and "." were outside the scope of the design; in some cases undefined behaviour given to such patterns may have made sense but that was mere accident.

If we were to give some defined behaviour to these patterns, updating the "Pattern Format" section of Documentation/gitignore.txt is the first thing to do. The text currently reads like this:

PATTERN FORMAT --------------

 - A blank line matches no files, so it can serve as a separator
   for readability.
 - A line starting with # serves as a comment.
 - An optional prefix '!' which 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.
 - If the pattern ends with a slash, it is removed for the
   purpose of the following description, but it would only find
   a match with a directory.  In other words, `foo/` will match a
   directory `foo` and paths underneath it, but will not match a
   regular file or a symbolic link `foo` (this is consistent
   with the way how pathspec works in general in git).
 - If the pattern does not contain a slash '/', git treats it as
   a shell glob pattern and checks for a match against the
   pathname relative to the location of the `.gitignore` file
   (relative to the toplevel of the work tree if not from a
   `.gitignore` file).
 - Otherwise, git treats the pattern as a shell glob suitable
   for consumption by fnmatch(3) with the FNM_PATHNAME flag:
   wildcards in the pattern will not match a / in the pathname.
   For example, "Documentation/{asterisk}.html" matches
   "Documentation/git.html" but not "Documentation/ppc/ppc.html"
   or "tools/perf/Documentation/perf.html".
 - A leading slash matches the beginning of the pathname.
   For example, "/{asterisk}.c" matches "cat-file.c" but not
   "mozilla-sha1/sha1.c".

I think adding the following before the 5th rule ("If the pattern does not contain a slash") would be sufficient:

 - If the pattern is a single dot and nothing else, it matches everything
   in the current directory.

So "./" in .gitignore or .gitattributes at the toplevel would match all the top-level directories and files but does not apply to the paths contained in the matched directories. "." in .gitignore or .gitattributes at the toplevel would match everything under the sun.

Personally I do not think it is an improvement. You can certainly say "we have one less undefined case and are more consistent", but the downside of that consistency is that it is very confusing and error prone for the end users. Would it be sensible to assume that users would not be surprised if ". text=auto" meant that the attribute applies to every file in the worktree?

Previous: Gioele BarabucciNext: Gioele Barabucci
Message 4 of 13 in “Git attributes ignored for root directory”
  1. Gioele BarabucciOct 4, 2011
  2. Michael HaggertyOct 5, 2011
  3. Gioele BarabucciOct 5, 2011
  4. Junio C HamanoOct 5, 2011
  5. Gioele BarabucciOct 5, 2011
  6. Junio C HamanoOct 5, 2011
  7. Gioele BarabucciOct 5, 2011
  8. Junio C HamanoOct 5, 2011
  9. Michael HaggertyOct 12, 2011
  10. Junio C HamanoOct 12, 2011
  11. Gioele BarabucciOct 13, 2011
  12. Johannes SixtOct 13, 2011
  13. Junio C HamanoOct 13, 2011

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.