I have a repository which has two submodules. Git is complaining when I run git submodule init
or git submodule update
, with the following error:
fatal: no submodule mapping found in .gitmodules for path 'AppName.xcodeproj/..Vendor/AFNetworking'
My submodules were not all in the same directory, and I decided to clean up the project. I used to have a directory called Vendor
which contained some of my submodules but I followed the directions here to remove the submodule from git. Then, I re-added the submodules in a new directory called submodules
.
One of my submodules is the AFNetworking
library, which I had added as a submodule in the initial Vendor directory. I removed it a while ago and re-added it as part of the clean up process. The app seemed to build just fine, and my git submodule
commands were working correctly. Now, when I check out on a different machine, it fails as described above.
My .gitmodules
file looks like this:
[submodule "submodules/AFNetworking"]
path = submodules/AFNetworking
url = https://github.com/AFNetworking/AFNetworking.git
[submodule "submodules/LNPopupController"]
path = submodules/LNPopupController
url = https://github.com/MosheBerman/LNPopupController.git
This seems normal, as git knows where my modules are, and all should be well. The same is true of my .git/config
file:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]:MosheBerman/theshmuz.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "submodules/AFNetworking"]
url = https://github.com/AFNetworking/AFNetworking.git
The error is subtle, and it took a while for me to realize it, but I noticed that the error message references the old Vendor
directory, which no longer exists.
I opened ./git/index
by directing the output of cat into a text file and using a text editor. Sure enough, AppName.xcodeproj/../Vendor/AFNetworking/
appears in the index. Could this be a bad gitlink? How do I clean this up so I can initialize and build my repo as normal?
I had tried removing the cached reference from the index from the root directory containing AppName.xcodeproj
before, like so:
git rm --cached /Vendor/AFNetworking
So, I recreated the folder hierarchy and I tried adding a dummy file inside /Vendor/AFNetworking.
I also tried adding a file called "AFNetworking" inside of Vendor
. Adding and then removing those files didn't do the trick.
I took another look at this problem and found a blog post (link) which explained the right way to inspect the index. It turns out that my index had the weird reference to the old submodule in it:
AppName.xcodeproj/../Vendor/AFNetworking.
The solution was to remove the file with exact listing from the index, like so:
git rm --cached AppName.xcodeproj/../Vendor/AFNetworking
Then I was able to run git submodule update
successfully. It looks like the index doesn't always match unix file-system relative paths, but it can be more specific in some cases. The Pro Git book had some information (in the print Chapter 9 edition, Chapter 10 online) that led me to suspect this, but it took the blog post for me to understand exactly how to open the index.
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