X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=submodules%2Fremove;h=f9436cead70e12fdd84b414fb746d3c89aff7e83;hb=HEAD;hp=4b38d1ae96e6469747cf95ffd36a6a09ca90bda1;hpb=d05bbf16af2379e816cbc5cdbf0984a13a62173d;p=git-scripts.git diff --git a/submodules/remove b/submodules/remove index 4b38d1a..f9436ce 100755 --- a/submodules/remove +++ b/submodules/remove @@ -1,8 +1,12 @@ #! /bin/sh # See https://stackoverflow.com/q/1260748/7976758 +case "$1" in + -c|--cached) cached=--cached; shift ;; +esac && + if [ $# != 1 ]; then - echo "Usage: $0 submodule_name" >&2 + echo "Usage: $0 [-c|--cached] submodule_name" >&2 exit 1 fi @@ -21,6 +25,14 @@ if [ -z "$path" ]; then exit 1 fi -git rm "$path" -rm -rf "git rev-parse --git-dir"/modules/"$name" -exec git config --remove-section submodule."$name" +git rm $cached "$path" && +rm -rf "`git rev-parse --git-dir`"/modules/"$name" && +git config --remove-section submodule."$name" && + +if [ \! -s .gitmodules ]; then + git rm -f .gitmodules +fi && + +if [ -z $(ls -A "`git rev-parse --git-dir`/modules") ]; then + exec rmdir "`git rev-parse --git-dir`/modules" +fi