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 into the /YATC directory
. I did git add .
in the /YATC directory, and only an empty TwitterTimeline directory was added to the repo. No other files were added. I later found out that there was already a .git
directory in TwitterTimeline. I think Xcode must have created that, although I don't recall ever asking it to.
Anyway, I deleted the TwitterTimeline/.git
directory. I went back up to /YATC
and tried to do git add .
there, and nothing happened. Meaning I immediately did git status
, and it said there was nothing to commit. 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 this?
Not sure exactly what's happening but I was in the same situation
git add -A .
I got around it by renaming the subdir, doing git add
from a parent dir, then renaming the subdir back to the original name. Somehow that seemed to get git back in a working state.
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:
I got this problem too,Here is my way to fix this:
git rm --cached directory
git add directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With