git-submodule-remove 641 B

123456789101112131415161718192021
  1. # vim:et sts=2 sw=2 ft=zsh
  2. local git_dir
  3. git_dir=$(git-dir) || return 1
  4. if [[ ${PWD} != $(git-root) ]]; then
  5. print "${0}: must be run from the root of the work tree" >&2
  6. return 1
  7. elif ! command git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then
  8. print "${0}: submodule not found: ${1}" >&2
  9. return 1
  10. fi
  11. command git config --file "${git_dir}/config" --remove-section "submodule.${1}" &>/dev/null
  12. command git config --file .gitmodules --remove-section "submodule.${1}" &>/dev/null
  13. command git add .gitmodules
  14. command git rm --cached "${1}" &>/dev/null
  15. rm -rf "${1}"
  16. rm -rf "${git_dir}/modules/${1}"
  17. return 0