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

Re: [bug] assertion in 2.8.4 triggering on old-ish worktree

From
Stefan Beller <sbeller@google.com>
Date
Jun 16, 2016, 19:48 UTC
Message-ID
<CAGZ79kZaZCwZ-cesB_voq0s0Qt+ipcgb6TkdzLE+EWSF_qRj7A@mail.gmail.com>
In-Reply-To
<xmqqbn31581d.fsf@gitster.mtv.corp.google.com>
On Thu, Jun 16, 2016 at 10:59 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 24 quoted lines
> Chris Packham <judge.packham@gmail.com> writes:
>
>> On Thu, Jun 16, 2016 at 4:59 PM, Chris Packham <judge.packham@gmail.com> wrote:
>>> Hi All,
>>>
>>> I have the git-sh-prompt configured in my .bashrc today I visited an
>>> old worktree that I haven't really touched in a few years (sorry can't
>>> remember the git version I was using back then). I received the
>>> following output when changing to the directory
>>>
>>> git: pathspec.c:317: prefix_pathspec: Assertion `item->nowildcard_len
>>> <= item->len && item->prefix <= item->len' failed.
>>>
>>> I assume it's one of the git invocations in git-sh-prompt that's
>>> hitting the assertion. Any thoughts on what might be triggering it?
>>> Any debug I can gather?
>>
>> A bit more info. The directory in question is a uninitialised
>> submodule. It doesn't trigger in the root of the parent project.
>
>
> Sounds like
> http://article.gmane.org/gmane.comp.version-control.git/283549
>

I looked into this. In pathspec.c#prefix_pathspec (the function that has this assertion at the end), the assertion can only trigger if PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE or PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP was given as these are the only places that reduce item->len.

I converted the example test case to follow our test syntax (module tab/whitespace issues):

test_expect_success 'remove submodule and add its files' '
    mkdir test &&
    (
        cd test &&
        git init sub &&
        (
            cd sub &&
            touch foo &&
            git add foo &&
            git commit -m "foo"
        ) &&
        git init &&
        git add sub &&
        rm -rf sub/.git &&
        (
            cd sub &&
            git add .
        )
    )
'

And the issue here is that the submodule $GIT_DIR was removed, so that the "git add ." was called with the parents $GIT_DIR, and a prefix of sub/ (the slash will be removed in PATHSPEC_STRIP_SUBMODULE_SLASH...) such that the length will be 3 ("sub") and the other (prefix, nowildcard_len) are still 4.

One fix would be to adjust prefix and nowildcard_len as well (in case they were as long as len, and now are overlength, if they were shorter, no need to cut off one)

However I think that is missleading.

So let's step back a bit and think about what should happen in the test case above. I think the users intent may be

    "remove the submodule and add the files
    directly to the regular tree".

However this would not happen in case we do the quickfix of cutting one off prefix and nowildcard_len, because we have similar thing as a D/F (directory/file) conflict, just that it is a TREE/SUBMODULE conflict.

In the parent project there is still a submodule recorded for sub/ but the user wants it to be a tree, so we would have to rewrite that.

Using "rm -rf sub/.git" is a bad UI for saying " I want this to be a native tree/blobs instead of a submodule", so I would expect that we need to have another command there eventually (git submodule convert-to-subtree ?)

Regarding the assert: We are sure it's a submodule related thing, so we can have a quite narrow warning there, roughly:

diff --git a/pathspec.c b/pathspec.c
index c9e9b6c..d0ea87a 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -313,8 +313,11 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
        }

        /* sanity checks, pathspec matchers assume these are sane */
-       assert(item->nowildcard_len <= item->len &&
-              item->prefix         <= item->len);
+       if (item->nowildcard_len <= item->len &&
+           item->prefix         <= item->len)
+               die (_("Path leads inside submodule '%s', but the submodule "
+                      "was not recognized, i.e. not initialized or deleted"),
+                      ce->name);
        return magic;
 }
Previous: Junio C HamanoNext: Chris Packham
Message 7 of 8 in “[bug] assertion in 2.8.4 triggering on old-ish worktree”
  1. Chris PackhamJun 16, 2016
  2. Chris PackhamJun 16, 2016
  3. Stefan BellerJun 16, 2016
  4. Dennis KaarsemakerJun 16, 2016
  5. Stefan BellerJun 16, 2016
  6. Junio C HamanoJun 16, 2016
  7. Stefan BellerJun 16, 2016
  8. Chris PackhamJun 17, 2016

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.