]> git.phdru.name Git - git-scripts.git/commitdiff
Feat(submodules): Add a script to remove a submodule
authorOleg Broytman <phd@phdru.name>
Sun, 11 Dec 2022 21:44:16 +0000 (00:44 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 11 Dec 2022 21:53:17 +0000 (00:53 +0300)
submodules/remove [new file with mode: 0755]

diff --git a/submodules/remove b/submodules/remove
new file mode 100755 (executable)
index 0000000..92efc14
--- /dev/null
@@ -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"