Why is git erroring with 'Assertion failed' on git add .?

后端 未结 4 1142
北荒
北荒 2021-02-02 12:32

I forked a repo, then cloned it to my Mac into a /YATC directory. I had a previously-created Xcode project (TwitterTimeline) in another directory, which I copied in

4条回答
  •  耶瑟儿~
    2021-02-02 12:56

    Basically the problem is known and it usually affects submodules. It's not Git bug, but basically instead of assert you should see the proper error that specific pathspec is part of the submodule.

    The following Git patch from Stefan Beller fixes that problem:

    --- a/pathspec.c
    +++ b/pathspec.c
    @@ -313,8 +313,23 @@ 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) {
    +       /* Historically this always was a submodule issue */
    +       for (i = 0; i < active_nr; i++) {
    +           struct cache_entry *ce = active_cache[i];
    +           int ce_len = ce_namelen(ce);
    +           int len = ce_len < item->len ? ce_len : item->len;
    +           if (!S_ISGITLINK(ce->ce_mode))
    +               continue;
    +           if (!memcmp(ce->name, item->match, len))
    +               die (_("Pathspec '%s' is in submodule '%.*s'"),
    +                   item->original, ce_len, ce->name);
    +       }
    +       /* The error is a new unknown bug */
    +       die ("BUG: item->nowildcard_len > item->len || item->prefix > item->len)");
    +   }
    +
        return magic;
     }
    

    One of the reason could be that the directory where you're adding the files is still registered as a submodule in the index, but actually it's not a valid git repository (e.g. it's missing .git directory).

    So you should either:

    • initialize and update your submodules by:

       git submodule init
       git submodule update
      

      Run from the parent directory where you had the error.

      Make sure all non-initialized submodules have empty directories, so move any files out of there temporary.

    • or if you don't need this submodule, remove it:

      git rm -f --cached subrepo
      

      Run from the parent directory where you had the error.

    Then try adding the files again.


    See also:

    • [PATCH] pathspec: give better message for submodule related pathspec error
    • Re: [PATCH] pathspec: adjust prefixlen after striping trailing slash
    • assert failed in submodule edge case,
    • "item->nowildcard_len" in Google.

提交回复
热议问题