From: Oleg Broytman Date: Sun, 11 Dec 2022 21:44:16 +0000 (+0300) Subject: Feat(submodules): Add a script to remove a submodule X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=d542fe583dbdee0911cc377758ad55cc47b46b7c;p=git-scripts.git Feat(submodules): Add a script to remove a submodule --- diff --git a/submodules/remove b/submodules/remove new file mode 100755 index 0000000..92efc14 --- /dev/null +++ b/submodules/remove @@ -0,0 +1,25 @@ +#! /bin/sh +# See https://stackoverflow.com/q/1260748/7976758 + +if [ $# != 1 ]; then + echo "Usage: $0 submodule_name" >&2 + exit 1 +fi + +cd `git rev-parse --show-toplevel` || exit 1 +if [ \! -f .gitmodules ]; then + echo "The command must be run in the top-level directory" >&2 + exit 1 +fi + +name="$1" +path="$(git config -f .gitmodules --get "submodule.$name.path")" + +if [ -z "$path" ]; then + echo "Error: submodule $name does not exist" >&2 + exit 1 +fi + +git submodule deinit -f -- "$path" +rm -rf .git/modules/"$name" +exec git rm -rf "$path"