You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
test -z "$1" && echo "submodule required" 1>&2 && exit 1
|
|
|
|
#cd "$(git root)"
|
|
|
|
test ! -f .gitmodules && echo ".gitmodules file not found" 1>&2 && exit 2
|
|
|
|
|
|
|
|
NAME="$(echo "$1" | sed 's/\/$//g')"
|
|
|
|
test -z \
|
|
|
|
"$(git config --file=.gitmodules submodule."$NAME".url)" \
|
|
|
|
&& echo "submodule not found" 1>&2 && exit 3
|
|
|
|
|
|
|
|
path="$(git config --file=.gitmodules submodule."$NAME".path)"
|
|
|
|
url="$(git config --file=.gitmodules submodule."$NAME".url)"
|
|
|
|
|
|
|
|
# 1. Delete the relevant section from .git/config and clean submodule files
|
|
|
|
git submodule deinit -f "$path" || exit 4
|
|
|
|
rmdir "$path"
|
|
|
|
rm -rf .git/modules/"$NAME"
|
|
|
|
# 2. Delete the relevant line from .gitmodules
|
|
|
|
git config --file=.gitmodules --remove-section submodule."$NAME"
|
|
|
|
git add .gitmodules
|
|
|
|
# 3. Run git rm --cached path_to_submodule
|
|
|
|
git rm --cached -rf "$path"
|
|
|
|
# 4. Need to confirm and commit the changes for yourself
|
|
|
|
echo
|
|
|
|
echo "Now submodule $NAME is deleted."
|
|
|
|
echo 'Confirm with `git submodule status` and commit the changes for yourself.'
|