I have a folder, which was a git repo. It contains some files and .gitmodules file. Now, when I do git init and then git submodule init, the latter
For zsh users, try my function which has DRY_RUN=1 support to see what commands will be ran and only uses git to parse the file instead of sed.
gsub_file() {(
set -eu
cd "$(git rev-parse --show-toplevel)"
submodule_paths=(
"${(@f)$(git config --file ./.gitmodules --get-regexp "path" | awk '{ print $2 }')}"
)
submodule_urls=(
"${(@f)$(git config --file ./.gitmodules --get-regexp "url" | awk '{ print $2 }')}"
)
submodule_branches=(
"${(@f)$(git config --file ./.gitmodules --get-regexp "branch" | awk '{ print $2 }')}"
)
sh_c() {
echo + "$*"
if [ "${DRY_RUN-}" ]; then
return
fi
eval "$@"
}
for (( i=1; i <= ${#submodule_paths[@]}; i++ )) do
p="${submodule_paths[$i]}"
if [ -d "$p" ]; then
continue
fi
url="${submodule_urls[$i]}"
unset b
if [ "${submodule_branches[$i]-}" ]; then
b="-b ${submodule_branches[$i]}"
fi
sh_c git submodule add "${b-}" "$url" "$p"
done
)}