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

Glob patterns w/ **; zero or more?

From
MNMaël Nison <nison.mael@gmail.com>
Date
Apr 16, 2023, 18:40 UTC
Message-ID
<CANiF4iAaWB9j+Mma0-yfp6GvoQuM4k_OBAXn0keR+vCg8PQjmA@mail.gmail.com>
Hi,

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.

For reference, the documentation is explicit that `**` is "zero or more", not "one or more", and it matches the behaviour from other glob implementations (emphasis mine):

> 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.
Also quoting the bash documentation for reference:
> globstar
> If set, the pattern ‘**’ used in a filename expansion context will match all files
> and zero or more directories and subdirectories. If the pattern is followed by
> a ‘/’, only directories and subdirectories match.
Next: Andreas Schwab
Message 1 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.