Created
February 16, 2016 14:58
-
-
Save ianblenke/21bc7ba721c7f91e6654 to your computer and use it in GitHub Desktop.
Fix submodule remotes to match .gitmodules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
find . -name '.gitmodules' | while read gitmodules; do | |
parent_path="$(echo $gitmodules | sed -e 's/.gitmodules//')" | |
git config -f $gitmodules --get-regexp '^submodule\..*\.path$' | | |
while read path_key path | |
do | |
url_key=$(echo $path_key | sed 's/\.path/.url/') | |
gitmodules_url=$(git config -f $gitmodules --get "$url_key") | |
submodule_path=$(echo "$url_key" | sed -e 's/^submodule.//' -e 's/.url$//') | |
( | |
cd ./$parent_path/$submodule_path | |
remote_url=$(git remote -v | grep origin | head -1 | awk '{print $2}') | |
if [ "$gitmodules_url" != "$remote_url" ]; then | |
git remote rename origin old-$(date +%Y%m%d%H%M%S) | |
git remote add origin $gitmodules_url | |
git fetch --all | |
fi | |
) | |
done | |
done | |
git submodule update --init --recursive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment