{"thread":{"id":"55551","subject":"[BUG] ** glob pattern in git diff doesn't match root directory","startedAt":"2021-04-24T03:26:47Z","lastAt":"2021-04-27T19:58:25Z","messageCount":7,"participants":["Shoaib Meenai","Felipe Contreras","=?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"422846","messageId":"79834D18-EAF4-4748-9B96-38AAA0760499@fb.com","threadId":"55551","inReplyTo":null,"subject":"[BUG] ** glob pattern in git diff doesn't match root directory","fromName":"Shoaib Meenai","fromEmail":"smeenai@fb.com","sentAt":"2021-04-24T02:52:21Z","receivedAt":"2021-04-24T03:26:47Z","isPatch":false,"sender":{"key":"smeenai@fb.com","avatar":null},"body":"Hi all,\n\nWhen I use a `**/` glob pattern with `git diff`, it doesn't seem to\nmatch in the root directory. The documentation for gitgnore says that a\nleading `**/` should match in all directories, and I would expect it to\nbehave the same way for `git diff`. For example:\n\n$ git --version\ngit version 2.31.1.527.g47e6f16901 # built from the `next` branch\n$ mkdir /tmp/globtest && cd /tmp/globtest\n$ git init\n$ echo foo > foo\n$ mkdir sub\n$ echo subfoo > sub/foo\n$ git add .\n$ git commit -m 'Initial commit'\n$ echo bar > foo\n$ echo subbar > sub/foo\n$ git --no-pager diff '**/foo'\ndiff --git a/sub/foo b/sub/foo\nindex ef7889f..2b2ab6c 100644\n--- a/sub/foo\n+++ b/sub/foo\n@@ -1 +1 @@\n-subfoo\n+subbar\n\nOnly the diff to `sub/foo` is printed, whereas I'd expect the change to\nthe top-level `foo` to be printed as well. `git diff '**foo'` does behave\nas I would expect. This also happens with a `**` in the middle of a\npattern; e.g., `sub/**/bar` will match `sub/dir/bar` but not `sub/bar`.\n\nAm I misunderstanding how `**` should work, or is this a bug?\n\nThanks,\nShoaib\n\n"},{"id":"422847","messageId":"608391297345f_10cb920875@natae.notmuch","threadId":"55551","inReplyTo":"79834D18-EAF4-4748-9B96-38AAA0760499@fb.com","subject":"RE: [BUG] ** glob pattern in git diff doesn't match root directory","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-04-24T03:31:53Z","receivedAt":"2021-04-24T03:32:03Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Shoaib Meenai wrote:\n> Am I misunderstanding how `**` should work, or is this a bug?\n\nI would say this is a bug, but I'm not familiar with pathspecs.\n\nI stumbled upoon a very similar issue (I wanted to find all the *.jpg in\nthe repository). I couldn't find another way to do it but:\n\n  git diff ':(glob)**/foo'\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"422913","messageId":"87k0oq21md.fsf@evledraar.gmail.com","threadId":"55551","inReplyTo":"79834D18-EAF4-4748-9B96-38AAA0760499@fb.com","subject":"Re: [BUG] ** glob pattern in git diff doesn't match root directory","fromName":"=?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-04-26T08:23:07Z","receivedAt":"2021-04-26T08:23:31Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, Apr 24 2021, Shoaib Meenai wrote:\n\n> Hi all,\n>\n> When I use a `**/` glob pattern with `git diff`, it doesn't seem to\n> match in the root directory. The documentation for gitgnore says that a\n> leading `**/` should match in all directories, and I would expect it to\n> behave the same way for `git diff`. For example:\n>\n> $ git --version\n> git version 2.31.1.527.g47e6f16901 # built from the `next` branch\n> $ mkdir /tmp/globtest && cd /tmp/globtest\n> $ git init\n> $ echo foo > foo\n> $ mkdir sub\n> $ echo subfoo > sub/foo\n> $ git add .\n> $ git commit -m 'Initial commit'\n> $ echo bar > foo\n> $ echo subbar > sub/foo\n> $ git --no-pager diff '**/foo'\n> diff --git a/sub/foo b/sub/foo\n> index ef7889f..2b2ab6c 100644\n> --- a/sub/foo\n> +++ b/sub/foo\n> @@ -1 +1 @@\n> -subfoo\n> +subbar\n>\n> Only the diff to `sub/foo` is printed, whereas I'd expect the change to\n> the top-level `foo` to be printed as well. `git diff '**foo'` does behave\n> as I would expect. This also happens with a `**` in the middle of a\n> pattern; e.g., `sub/**/bar` will match `sub/dir/bar` but not `sub/bar`.\n>\n> Am I misunderstanding how `**` should work, or is this a bug?\n\nIt's not a bug in behavior, but reading the documentation I think it's\nbuggy in describing how it works.\n\nThe behavior of ** here is to match anything, including a slash, but you\nyourself are providing the slash with \"**/\".\n\nThis behavior is different under :(glob) where we would match \"foo\" on\nthe top-level.\n\nSee t/t3070-wildmatch.sh, is particular the \"**/foo\" test-case.\n\nWe adopted this code from rsync originally, I think its manual page is\nbetter at describing how it works, as an aside I see they've since added\na \"***\" which we won't have, and maybe some other features.\n"},{"id":"422914","messageId":"87h7ju21kg.fsf@evledraar.gmail.com","threadId":"55551","inReplyTo":"608391297345f_10cb920875@natae.notmuch","subject":"Re: [BUG] ** glob pattern in git diff doesn't match root directory","fromName":"=?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-04-26T08:23:32Z","receivedAt":"2021-04-26T08:23:36Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sat, Apr 24 2021, Felipe Contreras wrote:\n\n> Shoaib Meenai wrote:\n>> Am I misunderstanding how `**` should work, or is this a bug?\n>\n> I would say this is a bug, but I'm not familiar with pathspecs.\n\nI replied on the \"is it a bug\" upthread...\n\n> I stumbled upoon a very similar issue (I wanted to find all the *.jpg in\n> the repository). I couldn't find another way to do it but:\n>\n>   git diff ':(glob)**/foo'\n\nMaybe I'm missing something, but if you want to find all *.jpg isn't\nthat just:\n\n    git diff '*.jpg'\n\n?\n"},{"id":"423039","messageId":"123C2F2F-7B85-4EDD-A8D9-172CA566391D@fb.com","threadId":"55551","inReplyTo":"608391297345f_10cb920875@natae.notmuch","subject":"Re: [BUG] ** glob pattern in git diff doesn't match root directory","fromName":"Shoaib Meenai","fromEmail":"smeenai@fb.com","sentAt":"2021-04-26T20:45:06Z","receivedAt":"2021-04-26T20:45:21Z","isPatch":false,"sender":{"key":"smeenai@fb.com","avatar":null},"body":"> On 4/23/21, 8:32 PM, \"Felipe Contreras\" <felipe.contreras@gmail.com> wrote:\n> Shoaib Meenai wrote:\n>> Am I misunderstanding how `**` should work, or is this a bug?\n>\n> I would say this is a bug, but I'm not familiar with pathspecs.\n>\n> I stumbled upoon a very similar issue (I wanted to find all the *.jpg in\n> the repository). I couldn't find another way to do it but:\n>\n>   git diff ':(glob)**/foo'\n\nAh, \"pathspec\" is the piece of vocabulary that I was missing. Looking at\nthe git documentation for pathspecs, I can see how this is supposed to\nbehave, and `:(glob)` is exactly the behavior I'm looking for. Thank you!\n\n>\n> Cheers.\n>\n> --\n> Felipe Contreras\n\n\n"},{"id":"423040","messageId":"CE391060-0F01-449A-BBAA-B0C577D759A6@fb.com","threadId":"55551","inReplyTo":"87k0oq21md.fsf@evledraar.gmail.com","subject":"Re: [BUG] ** glob pattern in git diff doesn't match root directory","fromName":"Shoaib Meenai","fromEmail":"smeenai@fb.com","sentAt":"2021-04-26T20:48:07Z","receivedAt":"2021-04-26T20:48:13Z","isPatch":false,"sender":{"key":"smeenai@fb.com","avatar":null},"body":"> On 4/26/21, 1:23 AM, \"=?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason\" <avarab@gmail.com> wrote:\n> On Sat, Apr 24 2021, Shoaib Meenai wrote:\n>\n>> Hi all,\n>>\n>> When I use a `**/` glob pattern with `git diff`, it doesn't seem to\n>> match in the root directory. The documentation for gitgnore says that a\n>> leading `**/` should match in all directories, and I would expect it to\n>> behave the same way for `git diff`. For example:\n>>\n>> $ git --version\n>> git version 2.31.1.527.g47e6f16901 # built from the `next` branch\n>> $ mkdir /tmp/globtest && cd /tmp/globtest\n>> $ git init\n>> $ echo foo > foo\n>> $ mkdir sub\n>> $ echo subfoo > sub/foo\n>> $ git add .\n>> $ git commit -m 'Initial commit'\n>> $ echo bar > foo\n>> $ echo subbar > sub/foo\n>> $ git --no-pager diff '**/foo'\n>> diff --git a/sub/foo b/sub/foo\n>> index ef7889f..2b2ab6c 100644\n>> --- a/sub/foo\n>> +++ b/sub/foo\n>> @@ -1 +1 @@\n>> -subfoo\n>> +subbar\n>>\n>> Only the diff to `sub/foo` is printed, whereas I'd expect the change to\n>> the top-level `foo` to be printed as well. `git diff '**foo'` does behave\n>> as I would expect. This also happens with a `**` in the middle of a\n>> pattern; e.g., `sub/**/bar` will match `sub/dir/bar` but not `sub/bar`.\n>>\n>> Am I misunderstanding how `**` should work, or is this a bug?\n>\n> It's not a bug in behavior, but reading the documentation I think it's\n> buggy in describing how it works.\n>\n> The behavior of ** here is to match anything, including a slash, but you\n> yourself are providing the slash with \"**/\".\n>\n> This behavior is different under :(glob) where we would match \"foo\" on\n> the top-level.\n>\n> See t/t3070-wildmatch.sh, is particular the \"**/foo\" test-case.\n>\n> We adopted this code from rsync originally, I think its manual page is\n> better at describing how it works, as an aside I see they've since added\n> a \"***\" which we won't have, and maybe some other features.\n\nGot it, thank you! I was providing a slash myself because my intention\nwas to only match paths that are exactly \"foo\", whereas e.g. '**foo'\nwould also match 'some_prefix_and_then_foo'. `:(glob)` does exactly what\nI want though; thank you.\n\n"},{"id":"423128","messageId":"60886cdb7c3a2_222c20818@natae.notmuch","threadId":"55551","inReplyTo":"87h7ju21kg.fsf@evledraar.gmail.com","subject":"Re: [BUG] ** glob pattern in git diff doesn't match root directory","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-04-27T19:58:19Z","receivedAt":"2021-04-27T19:58:25Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"=?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason wrote:\n> On Sat, Apr 24 2021, Felipe Contreras wrote:\n\n> > I stumbled upoon a very similar issue (I wanted to find all the *.jpg in\n> > the repository). I couldn't find another way to do it but:\n> >\n> >   git diff ':(glob)**/foo'\n> \n> Maybe I'm missing something, but if you want to find all *.jpg isn't\n> that just:\n> \n>     git diff '*.jpg'\n> \n> ?\n\nRight, actually I misremembered; it was all '.gitignore' files.\n\nIf I do '*.gitignore' that matches all the files, but also any\n$x.gitignore files. If I want only '.gitignore' files I need\n':(glob)**/.gitignore'.\n\nCheers.\n\n-- \nFelipe Contreras\n"}]}