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

I unlocked the repo and then cloned it on my Mac to the /YATC . I had a previously created Xcode project (TwitterTimeline) in another directory that I copied to the /YATC directory . I did git add . in the / YATC directory, and only the empty TwitterTimeline directory was added to the repo. No other files have been added. Later I learned that TwitterTimeline already has a .git directory. I think Xcode must have created this, although I don't remember ever being asked.

Anyway, I deleted the TwitterTimeline/.git . I went back to /YATC and tried to do git add . there, and nothing happened. Meaning: I immediately made git status , and he said there was nothing to do. Then I went down to the TwitterTimeline directory and did git add . and got the following:

 Assertion failed: (item->nowildcard_len <= item->len && item->prefix <= item->len), function prefix_pathspec, file pathspec.c, line 308. Abort trap: 6 

What is it?

+16
git xcode
Apr 21 '14 at 21:01
source share
4 answers

Not sure what's going on, but I was in the same situation

  • I moved one git repo inside another
  • deleted .git dir, thinking that it will become ordinary subdir
  • tried git add -A .
  • received a strange error message

I circumvented it by renaming subdir, doing git add from the parent directory, and then renaming subdir back to the original name. Somehow, it seems he has returned to working condition.

+28
May 03 '14 at 5:24
source share
β€” -

Basically, the problem is known and usually affects submodules. This is not a Git error, but basically, instead of assert, you should see the correct error that a particular pathspec is part of a submodule.

The following Git patch from Stefan Beller fixes this 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 reason may be that the directory into which you are adding files is still registered as a submodule in the index, but in fact it is not a valid Git repository (for example, the .git directory is missing).

So you should:

  • initialize and update your submodules by:

      git submodule init git submodule update 

    Run from the parent directory where the error was.

    Make sure that all uninitialized submodules have empty directories, so move any temporary files from them.

  • or if you do not need this submodule, delete it:

     git rm -f --cached subrepo 

    Run from the parent directory where the error was.

Then try adding files again.




See also:

+1
Dec 30 '16 at 0:05
source share

The only way I was able to get around this error after

  • Delete .git folder
  • git deinit
  • git rm
  • iterate over these links git fatal pathspec subodule , delete local repo , assert failed in submodule

you had to rename the directory and then add it again.

0
Oct 12 '16 at 18:48
source share

I have this problem too. Here is my way to fix this:

  • delete the .git folder in the submodule folder (if you have done this before, go 2)
  • then excute follow command, directory is the submodule folder of git rm --cached directory git add directory
  • then you can download this folder like the others.
0
Nov 01 '17 at 11:41
source share



All Articles