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
I got this problem too,Here is my way to fix this:
git rm --cached directory
git add directory
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:
The only way i was able to get around this error, after
git deinit
git rm
was to rename directory and then add it again.
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.