]> git.phdru.name Git - git-scripts.git/blob - submodules/remove
1db57c2f06353df4a4b405bd392fee3fb8f544a4
[git-scripts.git] / submodules / remove
1 #! /bin/sh
2 # See https://stackoverflow.com/q/1260748/7976758
3
4 if [ $# != 1 ]; then
5     echo "Usage: $0 submodule_name" >&2
6     exit 1
7 fi
8
9 cd "`git rev-parse --show-toplevel`" || exit 1
10 if [ \! -f .gitmodules ]; then
11     echo "Cannot find .gitmodules. The command must be run " >&2
12     echo "in the top-level directory of a repository with submodules" >&2
13     exit 1
14 fi
15
16 name="$1"
17 path="$(git config -f .gitmodules --get "submodule.$name.path")"
18
19 if [ -z "$path" ]; then
20     echo "Error: submodule $name does not exist" >&2
21     exit 1
22 fi
23
24 git rm "$path" &&
25 rm -rf "`git rev-parse --git-dir`"/modules/"$name" &&
26 git config --remove-section submodule."$name" &&
27
28 if [ \! -s .gitmodules ]; then
29     git rm -f .gitmodules
30 fi &&
31
32 if [ -z $(ls -A "`git rev-parse --git-dir`/modules") ]; then
33     exec rmdir "`git rev-parse --git-dir`/modules"
34 fi