For a CI build of a project with submodules, I want to make sure that the working tree exactly matches the state that is submitted in the central repository.
After fetching and checking out the revision of the superproject, I perform the following steps to update the submodules:
git submodule foreach 'git reset --hard && git clean -xdf'
git submodule update --init
This seems to work for all cases except if a submodule is removed in the central repository. In this case, the jobs working copy still contains the removed submodule.
Also, a git clean -xdf
on the superproject doesn't seem to touch a stale submodule.
So, is it possible to automatically detect stale local submodules and to have them removed?
The problem is that your repo's config remains totally contaminated with the stale submodule's data. I managed to get git clean -xdf
to work by cleaning up the repo config first.
I'm using git 1.8.1.3 from source, but the submodule removal is still a major headache. I am at a complete loss why any submodule info is stored in the repo config. We stopped using them altogether, and changed to subtree merges.
Let's say the stale submodule is in the directory foo
.
A submodule was deleted upstream, if it's still listed in your .git/config
file, but was deleted from .gitmodules
. You need to do 4 things now:
.git/config
rm foo/.git
rm -rf .git/modules/foo
git clean -xdf