{"thread":{"id":"42624","subject":"[bug] assertion in 2.8.4 triggering on old-ish worktree","startedAt":"2016-06-16T06:55:53Z","lastAt":"2016-06-17T02:41:23Z","messageCount":8,"participants":["Chris Packham","Stefan Beller","Dennis Kaarsemaker","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"289334","messageId":"CAFOYHZDw-P0ST8WKoSVxBpbFCiACZpgiDPMfw5MRtFTMosO0rg@mail.gmail.com","threadId":"42624","inReplyTo":null,"subject":"[bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2016-06-16T04:59:22Z","receivedAt":"2016-06-16T06:55:53Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"Hi All,\n\nI have the git-sh-prompt configured in my .bashrc today I visited an\nold worktree that I haven't really touched in a few years (sorry can't\nremember the git version I was using back then). I received the\nfollowing output when changing to the directory\n\ngit: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len\n<= item->len && item->prefix <= item->len' failed.\n\nI assume it's one of the git invocations in git-sh-prompt that's\nhitting the assertion. Any thoughts on what might be triggering it?\nAny debug I can gather?\n"},{"id":"289335","messageId":"CAFOYHZArnE6vJ0U1zJAxytCBJJU5M-VtHbct6Qq4VPfw7-T-2A@mail.gmail.com","threadId":"42624","inReplyTo":"CAFOYHZDw-P0ST8WKoSVxBpbFCiACZpgiDPMfw5MRtFTMosO0rg@mail.gmail.com","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2016-06-16T05:02:02Z","receivedAt":"2016-06-16T06:55:53Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.com> wrote:\n> Hi All,\n>\n> I have the git-sh-prompt configured in my .bashrc today I visited an\n> old worktree that I haven't really touched in a few years (sorry can't\n> remember the git version I was using back then). I received the\n> following output when changing to the directory\n>\n> git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len\n> <= item->len && item->prefix <= item->len' failed.\n>\n> I assume it's one of the git invocations in git-sh-prompt that's\n> hitting the assertion. Any thoughts on what might be triggering it?\n> Any debug I can gather?\n\nA bit more info. The directory in question is a uninitialised\nsubmodule. It doesn't trigger in the root of the parent project.\n"},{"id":"289368","messageId":"CAGZ79kZkWjaRGQ3Sz3ujWyjmKFRzZYCkeNVVNVhgihPVSi7jdQ@mail.gmail.com","threadId":"42624","inReplyTo":"CAFOYHZArnE6vJ0U1zJAxytCBJJU5M-VtHbct6Qq4VPfw7-T-2A@mail.gmail.com","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-06-16T16:31:28Z","receivedAt":"2016-06-16T16:31:44Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Jun 15, 2016 at 10:02 PM, Chris Packham <judge.packham@gmail.com> wrote:\n> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.com> wrote:\n>> Hi All,\n>>\n>> I have the git-sh-prompt configured in my .bashrc today I visited an\n>> old worktree that I haven't really touched in a few years (sorry can't\n>> remember the git version I was using back then). I received the\n>> following output when changing to the directory\n>>\n>> git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len\n>> <= item->len && item->prefix <= item->len' failed.\n>>\n>> I assume it's one of the git invocations in git-sh-prompt that's\n>> hitting the assertion. Any thoughts on what might be triggering it?\n>> Any debug I can gather?\n\nThe first step would be to identify which git command is actually causing it.\nCan you take your  git-sh-prompt and run it step by step to figure out what\ncommand is failing?\n\nThe next step after that would be to see if we can reproduce it in a reduced\ntest case (with no real data) so we can add a regression test and a fix for it.\n\n>\n> A bit more info. The directory in question is a uninitialised\n> submodule. It doesn't trigger in the root of the parent project.\n\nso it's a\n\n    cd submodule\n    git <command>\n\nthat is failing?\n\nThanks,\nStefan\n\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"289370","messageId":"1466096135.28161.9.camel@kaarsemaker.net","threadId":"42624","inReplyTo":"CAFOYHZArnE6vJ0U1zJAxytCBJJU5M-VtHbct6Qq4VPfw7-T-2A@mail.gmail.com","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Dennis Kaarsemaker","fromEmail":"dennis@kaarsemaker.net","sentAt":"2016-06-16T16:55:35Z","receivedAt":"2016-06-16T16:55:55Z","isPatch":false,"sender":{"key":"dennis@kaarsemaker.net","avatar":"https://avatars.githubusercontent.com/u/200649?v=4"},"body":"On do, 2016-06-16 at 17:02 +1200, Chris Packham wrote:\n> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.c\n> om> wrote:\n> > \n> > Hi All,\n> > \n> > I have the git-sh-prompt configured in my .bashrc today I visited\n> > an\n> > old worktree that I haven't really touched in a few years (sorry\n> > can't\n> > remember the git version I was using back then). I received the\n> > following output when changing to the directory\n> > \n> > git: pathspec.c:317: prefix_pathspec: Assertion `item-\n> > >nowildcard_len\n> > <= item->len && item->prefix <= item->len' failed.\n> > \n> > I assume it's one of the git invocations in git-sh-prompt that's\n> > hitting the assertion. Any thoughts on what might be triggering it?\n> > Any debug I can gather?\n> A bit more info. The directory in question is a uninitialised\n> submodule. It doesn't trigger in the root of the parent project.\n\nThat very much smells like a class of bugs we've seen before, with git\ngetting confused around submodules. See also for example\n\nhttps://www.mail-archive.com/git@vger.kernel.org/msg68447.html\n\nI don't think an accepted fix exists yet.\n\nD.\n"},{"id":"289371","messageId":"CAGZ79kbw=XbqmjPQYMsG_F9FYx4o9wY5DpneBXX7RSBUeQ=3CA@mail.gmail.com","threadId":"42624","inReplyTo":"1466096135.28161.9.camel@kaarsemaker.net","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-06-16T16:59:44Z","receivedAt":"2016-06-16T16:59:50Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Jun 16, 2016 at 9:55 AM, Dennis Kaarsemaker\n<dennis@kaarsemaker.net> wrote:\n> On do, 2016-06-16 at 17:02 +1200, Chris Packham wrote:\n>> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.c\n>> om> wrote:\n>> >\n>> > Hi All,\n>> >\n>> > I have the git-sh-prompt configured in my .bashrc today I visited\n>> > an\n>> > old worktree that I haven't really touched in a few years (sorry\n>> > can't\n>> > remember the git version I was using back then). I received the\n>> > following output when changing to the directory\n>> >\n>> > git: pathspec.c:317: prefix_pathspec: Assertion `item-\n>> > >nowildcard_len\n>> > <= item->len && item->prefix <= item->len' failed.\n>> >\n>> > I assume it's one of the git invocations in git-sh-prompt that's\n>> > hitting the assertion. Any thoughts on what might be triggering it?\n>> > Any debug I can gather?\n>> A bit more info. The directory in question is a uninitialised\n>> submodule. It doesn't trigger in the root of the parent project.\n>\n> That very much smells like a class of bugs we've seen before, with git\n> getting confused around submodules. See also for example\n>\n> https://www.mail-archive.com/git@vger.kernel.org/msg68447.html\n>\n> I don't think an accepted fix exists yet.\n\nThanks for pointing me at that report. I was not aware of this \"class of bugs\",\nI'll see if I can fix it.\n\nThanks,\nStefan\n\n>\n> D.\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"289376","messageId":"xmqqbn31581d.fsf@gitster.mtv.corp.google.com","threadId":"42624","inReplyTo":"CAFOYHZArnE6vJ0U1zJAxytCBJJU5M-VtHbct6Qq4VPfw7-T-2A@mail.gmail.com","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-06-16T17:59:42Z","receivedAt":"2016-06-16T17:59:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Chris Packham <judge.packham@gmail.com> writes:\n\n> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.com> wrote:\n>> Hi All,\n>>\n>> I have the git-sh-prompt configured in my .bashrc today I visited an\n>> old worktree that I haven't really touched in a few years (sorry can't\n>> remember the git version I was using back then). I received the\n>> following output when changing to the directory\n>>\n>> git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len\n>> <= item->len && item->prefix <= item->len' failed.\n>>\n>> I assume it's one of the git invocations in git-sh-prompt that's\n>> hitting the assertion. Any thoughts on what might be triggering it?\n>> Any debug I can gather?\n>\n> A bit more info. The directory in question is a uninitialised\n> submodule. It doesn't trigger in the root of the parent project.\n\n\nSounds like\nhttp://article.gmane.org/gmane.comp.version-control.git/283549\n\n"},{"id":"289389","messageId":"CAGZ79kZaZCwZ-cesB_voq0s0Qt+ipcgb6TkdzLE+EWSF_qRj7A@mail.gmail.com","threadId":"42624","inReplyTo":"xmqqbn31581d.fsf@gitster.mtv.corp.google.com","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-06-16T19:48:11Z","receivedAt":"2016-06-16T19:48:17Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Jun 16, 2016 at 10:59 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Chris Packham <judge.packham@gmail.com> writes:\n>\n>> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.com> wrote:\n>>> Hi All,\n>>>\n>>> I have the git-sh-prompt configured in my .bashrc today I visited an\n>>> old worktree that I haven't really touched in a few years (sorry can't\n>>> remember the git version I was using back then). I received the\n>>> following output when changing to the directory\n>>>\n>>> git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len\n>>> <= item->len && item->prefix <= item->len' failed.\n>>>\n>>> I assume it's one of the git invocations in git-sh-prompt that's\n>>> hitting the assertion. Any thoughts on what might be triggering it?\n>>> Any debug I can gather?\n>>\n>> A bit more info. The directory in question is a uninitialised\n>> submodule. It doesn't trigger in the root of the parent project.\n>\n>\n> Sounds like\n> http://article.gmane.org/gmane.comp.version-control.git/283549\n>\n\nI looked into this. In pathspec.c#prefix_pathspec (the function\nthat has this assertion at the end), the assertion can only\ntrigger if PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE\nor PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP was given\nas these are the only places that reduce item->len.\n\nI converted the example test case to follow our test syntax\n(module tab/whitespace issues):\n\ntest_expect_success 'remove submodule and add its files' '\n    mkdir test &&\n    (\n        cd test &&\n        git init sub &&\n        (\n            cd sub &&\n            touch foo &&\n            git add foo &&\n            git commit -m \"foo\"\n        ) &&\n        git init &&\n        git add sub &&\n        rm -rf sub/.git &&\n        (\n            cd sub &&\n            git add .\n        )\n    )\n'\n\nAnd the issue here is that the submodule $GIT_DIR\nwas removed, so that the \"git add .\" was called with\nthe parents $GIT_DIR, and a prefix of sub/\n(the slash will be removed in PATHSPEC_STRIP_SUBMODULE_SLASH...)\nsuch that the length will be 3 (\"sub\") and the other\n(prefix, nowildcard_len) are still 4.\n\nOne fix would be to adjust prefix and nowildcard_len\nas well (in case they were as long as len, and now are\noverlength, if they were shorter, no need to cut off one)\n\nHowever I think that is missleading.\n\nSo let's step back a bit and think about what should happen\nin the test case above. I think the users intent may be\n\n    \"remove the submodule and add the files\n    directly to the regular tree\".\n\nHowever this would not happen in case we do the quickfix\nof cutting one off prefix and nowildcard_len, because\nwe have similar thing as a D/F (directory/file) conflict,\njust that it is a TREE/SUBMODULE conflict.\n\nIn the parent project there is still a submodule recorded for\nsub/ but the user wants it to be a tree, so we would have\nto rewrite that.\n\nUsing \"rm -rf sub/.git\" is a bad UI for saying \" I want this to be\na native tree/blobs instead of a submodule\", so I would expect\nthat we need to have another command there eventually\n(git submodule convert-to-subtree ?)\n\nRegarding the assert:\nWe are sure it's a submodule related thing, so we can\nhave a quite narrow warning there, roughly:\n\ndiff --git a/pathspec.c b/pathspec.c\nindex c9e9b6c..d0ea87a 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -313,8 +313,11 @@ static unsigned prefix_pathspec(struct pathspec_item *item,\n        }\n\n        /* sanity checks, pathspec matchers assume these are sane */\n-       assert(item->nowildcard_len <= item->len &&\n-              item->prefix         <= item->len);\n+       if (item->nowildcard_len <= item->len &&\n+           item->prefix         <= item->len)\n+               die (_(\"Path leads inside submodule '%s', but the submodule \"\n+                      \"was not recognized, i.e. not initialized or deleted\"),\n+                      ce->name);\n        return magic;\n }\n"},{"id":"289418","messageId":"CAFOYHZAnx-sg41OdFnbfgOkggfKCdAKXuMRXuKcbzaJibwR2Rw@mail.gmail.com","threadId":"42624","inReplyTo":"CAGZ79kZaZCwZ-cesB_voq0s0Qt+ipcgb6TkdzLE+EWSF_qRj7A@mail.gmail.com","subject":"Re: [bug] assertion in 2.8.4 triggering on old-ish worktree","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2016-06-17T02:41:16Z","receivedAt":"2016-06-17T02:41:23Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"On Fri, Jun 17, 2016 at 7:48 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Thu, Jun 16, 2016 at 10:59 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Chris Packham <judge.packham@gmail.com> writes:\n>>\n>>> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.com> wrote:\n>>>> Hi All,\n>>>>\n>>>> I have the git-sh-prompt configured in my .bashrc today I visited an\n>>>> old worktree that I haven't really touched in a few years (sorry can't\n>>>> remember the git version I was using back then). I received the\n>>>> following output when changing to the directory\n>>>>\n>>>> git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len\n>>>> <= item->len && item->prefix <= item->len' failed.\n>>>>\n>>>> I assume it's one of the git invocations in git-sh-prompt that's\n>>>> hitting the assertion. Any thoughts on what might be triggering it?\n>>>> Any debug I can gather?\n>>>\n>>> A bit more info. The directory in question is a uninitialised\n>>> submodule. It doesn't trigger in the root of the parent project.\n\nThe command that fails appears to be 'git check-ignore -q .'\n\n>>\n>>\n>> Sounds like\n>> http://article.gmane.org/gmane.comp.version-control.git/283549\n>>\n>\n> I looked into this. In pathspec.c#prefix_pathspec (the function\n> that has this assertion at the end), the assertion can only\n> trigger if PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE\n> or PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP was given\n> as these are the only places that reduce item->len.\n>\n<snip>\n\n> Regarding the assert:\n> We are sure it's a submodule related thing, so we can\n> have a quite narrow warning there, roughly:\n>\n> diff --git a/pathspec.c b/pathspec.c\n> index c9e9b6c..d0ea87a 100644\n> --- a/pathspec.c\n> +++ b/pathspec.c\n> @@ -313,8 +313,11 @@ static unsigned prefix_pathspec(struct pathspec_item *item,\n>         }\n>\n>         /* sanity checks, pathspec matchers assume these are sane */\n> -       assert(item->nowildcard_len <= item->len &&\n> -              item->prefix         <= item->len);\n> +       if (item->nowildcard_len <= item->len &&\n> +           item->prefix         <= item->len)\n> +               die (_(\"Path leads inside submodule '%s', but the submodule \"\n> +                      \"was not recognized, i.e. not initialized or deleted\"),\n> +                      ce->name);\n\nThis certainly would have pointed out the uninitialised state of my\nsetup in this case.\n\n>         return magic;\n>  }\n"}]}