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

Re: [PATCH 8/8] Support "**" wildcard in .gitignore and .gitattributes

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Oct 10, 2012, 05:40 UTC
Message-ID
<CACsJy8AW4bCrXZtNtpYGT4=Z72u=Ge2OuX1sG3xs_jUx9gRfPw@mail.gmail.com>
In-Reply-To
<5073D8FF.8080503@alum.mit.edu>
On Tue, Oct 9, 2012 at 2:57 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 18 quoted lines
>> + - A trailing "/**" matches everything inside. For example,
>> +   "abc/**" is equivalent to "`/abc/`".
>
> It seems odd that you add a leading slash in this example.  I assume
> that is because of the rule that a pattern containing a slash is
> considered anchored at the current directory. But I find it confusing
> because the addition of the leading slash is not part of the rule you
> are trying to illustrate here, and is therefore a distraction.  I
> suggest that you write either
>
> - A trailing "/**" matches everything inside. For example,
>   "/abc/**" is equivalent to "`/abc/`".
>
> or
>
> - A trailing "/**" matches everything inside. For example,
>   "abc/**" is equivalent to "`abc/`" (which is also equivalent
>   to "`/abc/`").

The tricky thing in .gitignore is that the last '/' alone does not imply anchor. So "abc/" means match _directory_ abc anywhere in worktree. So the former is probably better. I should also add a note here (or in gitattributes.txt) about the difference between "/abc/*" and "/abc/**". The former assigns attributes to all files directly under abc (e.g. depth 1), the latter infinite depth.

Show 18 quoted lines
>> + - A slash followed by two consecutive asterisks then a slash
>> +   matches zero or more directories. For example, "`a/**/b`"
>> +   matches "`a/b`", "`a/x/b`", "`a/x/y/b`" and so on.
>> +
>> + - Consecutive asterisks otherwise are treated like normal
>> +   asterisk wildcards.
>> +
>
> I don't like the last rule.  (1) This construct is superfluous; why
> wouldn't the user just use a single asterisk?  (2) Allowing this
> construct means that it could appear in .gitignore files, creating
> unnecessary confusion: extrapolating from the other meanings of "**"
> users would expect that it would somehow match slashes.  (3) It is
> conceivable (though admittedly unlikely) that we might want to assign a
> distinct meaning to this construct in the future, and accepting it now
> as a different way to spell "*" would prevent such a change.
>
> Perhaps this rule was intended for backwards compatibility?

We break backwards compatibility already. Existing "**/" or "/**" patterns now behave differently.

> I think it would be preferable to say that other uses of consecutive
> asterisks are undefined, and probably make them trigger a warning.

Instead of undefined, we can reject the pattern as "broken". I have to check how fnmatch/wildmatch deals with broken patterns (it must do). If it returns a different code for broken patterns, then we can warn users, which is not limited in just "**" breakage.

-- 
Duy
Previous: Michael Haggerty
Message 15 of 15 in “wildmatch take 3”
  1. 0/8 wildmatch take 3Nguyễn Thái Ngọc Duy, Oct 9, 2012
  2. 1/8 Import wildmatch from rsyncNguyễn Thái Ngọc Duy, Oct 9, 2012
  3. 2/8 wildmatch: remove unnecessary functionsNguyễn Thái Ngọc Duy, Oct 9, 2012
  4. 3/8 Integrate wildmatch to gitNguyễn Thái Ngọc Duy, Oct 9, 2012
  5. 4/8 wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy, Oct 9, 2012
  6. Junio C HamanoOct 9, 2012
  7. Nguyen Thai Ngoc DuyOct 10, 2012
  8. Junio C HamanoOct 10, 2012
  9. Nguyen Thai Ngoc DuyOct 10, 2012
  10. 5/8 wildmatch: fix case-insensitive matchingNguyễn Thái Ngọc Duy, Oct 9, 2012
  11. 6/8 wildmatch: adjust "**" behaviorNguyễn Thái Ngọc Duy, Oct 9, 2012
  12. 7/8 wildmatch: make /**/ match zero or more directoriesNguyễn Thái Ngọc Duy, Oct 9, 2012
  13. 8/8 Support "**" wildcard in .gitignore and .gitattributesNguyễn Thái Ngọc Duy, Oct 9, 2012
  14. Michael HaggertyOct 9, 2012
  15. Nguyen Thai Ngoc DuyOct 10, 2012

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.