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

Re: Oddities in gitignore matching

From
John Thorvald Wodder II <jwodder@gmail.com>
Date
Jun 28, 2022, 13:48 UTC
Message-ID
<0871A57F-4AF4-4F45-AC56-10C1817761BB@gmail.com>
In-Reply-To
<72a1a225-5d84-56c3-2652-ec7c17c18cbd@gmail.com>
On 2022 Jun 28, at 05:13, Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 7 quoted lines
> 
> Hi John
> 
> On 26/06/2022 20:34, John Thorvald Wodder II wrote:
>> First: I've found that the pattern "foo**/bar" causes the path "foo/glarch/bar" (as well as "foobie/glarch/bar") to be ignored.  However, the gitignore(5) documentation states that "**/" only has special meaning when it's "leading"; in other circumstances, the double star should be treated the same as a single star (and "foo*/bar" does not match "foo/glarch/bar").  Is this behavior of non-leading "**/" deliberate or a bug?
> 
> I've no idea if it is deliberate or not but it seems reasonable and I think it matches shells like fish, tcsh and zsh though not bash (I think our documented behavior matches bash).
OK, but it turns out that "foo**/bar" also matches just "foobar", no slash, which definitely seems wrong.
>> Interestingly, checking the pattern with the wildmatch test-tool (`t/helper/test-tool wildmatch wildmatch foo/glarch/bar 'foo**/bar'`) shows that the pattern should not match the path.
>> Second: The pattern "[[:space:]]" does not match 0x0B (\v, vertical tab) or 0x0C (\f, form feed) despite the fact that the C isspace() function accepts these characters, and I cannot figure out the cause for this discrepancy.  (The pattern does match the other characters that isspace() accepts, though — tab, line feed, carriage return, and space character.)  The wildmatch test-tool agrees with this behavior, though.
> 
> This is because git defines its own isspace() that does not treat '\v' or '\f' as whitespace (see git-compat-util.h and ctype.c). I'm not sure why we exclude those characters, I think the reason for defining our own isspace() is to avoid the locale dependent behaviour of the standard version.
Thank you for the explanation.
---
Through further experimentation, I've discovered a fourth oddity with gitignore: If "foo//" (with two or more trailing slashes) is added to .gitignore and `mkdir -p foo/bar` is run, then `git status --ignored=matching --porcelain` won't show "foo/" or "foo/bar/" at all, which is something I'd previously only encountered for completely empty top-level directories.  This holds true no matter how deep or wide you make the directory tree at "foo/", as long as it's all-directories; once a file gets added somewhere under "foo/", the "git status" command shows "foo/" as ignored.
-- John Wodder
Previous: Phillip WoodNext: John Thorvald Wodder II
Message 3 of 5 in “Oddities in gitignore matching”
  1. John Thorvald Wodder IIJun 26, 2022
  2. Phillip WoodJun 28, 2022
  3. John Thorvald Wodder IIJun 28, 2022
  4. John Thorvald Wodder IIJun 28, 2022
  5. Phillip WoodJun 29, 2022

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.