]> git.phdru.name Git - git-scripts.git/blob - submodules/remove
Feat(submodules/remove): Improve error message
[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 "The command must be run in the top-level directory" >&2
12     echo "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/modules/"$name"
26 exec git config --remove-section submodule."$name"