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

Re: Glob patterns w/ **; zero or more?

From
Andreas Schwab <schwab@linux-m68k.org>
Date
Apr 16, 2023, 19:04 UTC
Message-ID
<87ttxfsl5w.fsf@igel.home>
In-Reply-To
<CANiF4iAaWB9j+Mma0-yfp6GvoQuM4k_OBAXn0keR+vCg8PQjmA@mail.gmail.com>
On Apr 16 2023, Maël Nison wrote:
Show 6 quoted lines
> I noticed that, in a repo with a single `main.c` file, `git ls-files
> './**/main.c'` (note the surrounding quotes, to avoid shell globbing)
> returns no result even though `git ls-files main.c` does. It however
> can find any `main.c` file located in a subdirectory, suggesting `**`
> is interpreted as "one or more" rather than "zero or more". Can you
> confirm it'd be a bug? I checked in both 2.38 and 2.40.

By default, pathspec matching does not take "**" specially, making it equivalen to "*", but it can match "/". Thus "./**/main.c" is the same as "*/main.c" (the leading "./" always matches) and matches paths with at least one "/" in it (thus "*/main.c" does not match "main.c").

If you use ":(glob)./**/main.c", it uses shell glob matching, where "**" is special and "/**/" can match "/", but "*" does not match "/".

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Previous: Maël Nison
Message 2 of 2 in “Glob patterns w/ **; zero or more?”
  1. Maël NisonApr 16, 2023
  2. Andreas SchwabApr 16, 2023

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.