2 # See https://stackoverflow.com/q/1260748/7976758
5 -c|--cached) cached=--cached; shift ;;
9 echo "Usage: $0 [-c|--cached] submodule_name" >&2
13 cd "`git rev-parse --show-toplevel`" || exit 1
14 if [ \! -f .gitmodules ]; then
15 echo "Cannot find .gitmodules. The command must be run " >&2
16 echo "in the top-level directory of a repository with submodules" >&2
21 path="$(git config -f .gitmodules --get "submodule.$name.path")"
23 if [ -z "$path" ]; then
24 echo "Error: submodule $name does not exist" >&2
28 git rm $cached "$path" &&
29 rm -rf "`git rev-parse --git-dir`"/modules/"$name" &&
30 git config --remove-section submodule."$name" &&
32 if [ \! -s .gitmodules ]; then
36 if [ -z $(ls -A "`git rev-parse --git-dir`/modules") ]; then
37 exec rmdir "`git rev-parse --git-dir`/modules"