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

Re: [BUG] ** glob pattern in git diff doesn't match root directory

From
=?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason <avarab@gmail.com>
Date
Apr 26, 2021, 08:23 UTC
Message-ID
<87k0oq21md.fsf@evledraar.gmail.com>
In-Reply-To
<79834D18-EAF4-4748-9B96-38AAA0760499@fb.com>
On Sat, Apr 24 2021, Shoaib Meenai wrote:
Show 33 quoted lines
> Hi all,
>
> When I use a `**/` glob pattern with `git diff`, it doesn't seem to
> match in the root directory. The documentation for gitgnore says that a
> leading `**/` should match in all directories, and I would expect it to
> behave the same way for `git diff`. For example:
>
> $ git --version
> git version 2.31.1.527.g47e6f16901 # built from the `next` branch
> $ mkdir /tmp/globtest && cd /tmp/globtest
> $ git init
> $ echo foo > foo
> $ mkdir sub
> $ echo subfoo > sub/foo
> $ git add .
> $ git commit -m 'Initial commit'
> $ echo bar > foo
> $ echo subbar > sub/foo
> $ git --no-pager diff '**/foo'
> diff --git a/sub/foo b/sub/foo
> index ef7889f..2b2ab6c 100644
> --- a/sub/foo
> +++ b/sub/foo
> @@ -1 +1 @@
> -subfoo
> +subbar
>
> Only the diff to `sub/foo` is printed, whereas I'd expect the change to
> the top-level `foo` to be printed as well. `git diff '**foo'` does behave
> as I would expect. This also happens with a `**` in the middle of a
> pattern; e.g., `sub/**/bar` will match `sub/dir/bar` but not `sub/bar`.
>
> Am I misunderstanding how `**` should work, or is this a bug?

It's not a bug in behavior, but reading the documentation I think it's buggy in describing how it works.

The behavior of ** here is to match anything, including a slash, but you yourself are providing the slash with "**/".

This behavior is different under :(glob) where we would match "foo" on the top-level.

See t/t3070-wildmatch.sh, is particular the "**/foo" test-case.

We adopted this code from rsync originally, I think its manual page is better at describing how it works, as an aside I see they've since added a "***" which we won't have, and maybe some other features.

Previous: Shoaib MeenaiNext: Shoaib Meenai
Message 6 of 7 in “[BUG] ** glob pattern in git diff doesn't match root directory”
  1. Shoaib MeenaiApr 24, 2021
  2. Felipe ContrerasApr 24, 2021
  3. =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= BjarmasonApr 26, 2021
  4. Felipe ContrerasApr 27, 2021
  5. Shoaib MeenaiApr 26, 2021
  6. =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= BjarmasonApr 26, 2021
  7. Shoaib MeenaiApr 26, 2021

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.