From 253501a2300926c3f96ec5470f9232272dcf21ff Mon Sep 17 00:00:00 2001 From: druckdev <63563978+druckdev@users.noreply.github.com> Date: Sun, 13 Sep 2020 17:14:50 +0200 Subject: [PATCH] Add git-submodule-rm Add function git-submodule-rm that deinits and removes a submodule from a git repo. --- .config/zsh/plugins/functionsPost.zsh | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.config/zsh/plugins/functionsPost.zsh b/.config/zsh/plugins/functionsPost.zsh index 32ee895..49d35f4 100644 --- a/.config/zsh/plugins/functionsPost.zsh +++ b/.config/zsh/plugins/functionsPost.zsh @@ -397,6 +397,35 @@ glog() { fi } +git-submodule-rm() { + # Exit if not in git repo + local toplevel="$(git rev-parse --show-toplevel)" || return + + # Exit if no arguements were given + [ $# -gt 0 ] || return + + local separator="" + for arg in "$@"; do + printf "$separator" + + # argument relative from git toplevel + local arg_from_git="${${arg:A}##$toplevel/}" + # argument has to exist + [ -e "$arg" ] || continue + # argument has to exist in repo + [ -e "$toplevel/$arg_from_git" ] || continue + # has to be a submodule + [ -e "$toplevel/.git/modules/$arg_from_git" ] || continue + + git submodule deinit -f "$arg" + echo "command rm -rf \"$toplevel/.git/modules/$arg_from_git\"" + command rm -rf "$toplevel/.git/modules/$arg_from_git" + git rm -f "$arg" + + separator="\n" + done +} + safe-remove() { [ $# -gt 0 ] || return 1 [ -e "$1" ] || return 1