Files
dotfiles/.config/zsh/autoload/git/git-submodule-rm
Julian Prein 65fc5efdec git:submodule-rm: Update to current .git structure
Update the function to use the current `.git/modules/` structure, by
only using the basename of the path.

I am not sure when this was changed and too lazy right now to find it
out.
2022-07-12 21:00:10 +02:00

35 lines
816 B
Bash
Executable File

#!/usr/bin/env zsh
## Author: druckdev
## Created: 2020-09-13
##
## Completely remove a git submodule.
local toplevel
# Exit if not in git repo
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/${1:t}" ]] || 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