refactor(submodules): improve old submodule cleanup in add-submodules.sh

This commit is contained in:
2026-02-05 21:52:45 +02:00
parent 0e69b7cb16
commit 08de5ea4a6

View File

@@ -42,26 +42,64 @@ done
# Mark certain repositories shallow # Mark certain repositories shallow
git config -f .gitmodules submodule.antidote.shallow true git config -f .gitmodules submodule.antidote.shallow true
# remove old submodules _log() {
folders=( if command -v msgr > /dev/null 2>&1; then
"config/tmux/plugins/tpm" msgr run_done "$1"
"config/tmux/plugins/tmux" else
"config/tmux/plugins/tmux-menus" echo " [ok] $1"
"tools/dotbot-crontab" fi
"tools/dotbot-snap" }
"config/tmux/plugins/tmux-window-name"
"config/tmux/plugins/tmux-sensible" remove_old_submodule() {
"config/tmux/plugins/tmux-mode-indicator" local name="$1" path="$2"
"config/tmux/plugins/tmux-yank"
"config/tmux/plugins/tmux-fzf-url" # Remove working tree
"config/nvim-kickstart" if [ -d "$path" ]; then
"local/bin/asdf" rm -rf "$path"
"local/asdf" _log "Removed $path"
"tools/dotbot-asdf" fi
# Remove stale git index entry
git rm --cached "$path" 2> /dev/null || true
# Remove .git/config section keyed by path
git config --remove-section "submodule.$path" 2> /dev/null || true
# Skip name-based cleanup if no submodule name provided
[ -z "$name" ] && return 0
# Remove .git/config section keyed by name
git config --remove-section "submodule.$name" 2> /dev/null || true
# Remove .git/modules/<name>/ cached repository
if [ -d ".git/modules/$name" ]; then
rm -rf ".git/modules/$name"
_log "Removed .git/modules/$name"
fi
}
# remove old submodules (name:path pairs)
old_submodules=(
"tmux/tpm:config/tmux/plugins/tpm"
":config/tmux/plugins/tmux"
"tmux/tmux-menus:config/tmux/plugins/tmux-menus"
"dotbot-crontab:tools/dotbot-crontab"
"dotbot-snap:tools/dotbot-snap"
"tmux/tmux-window-name:config/tmux/plugins/tmux-window-name"
"tmux/tmux-sensible:config/tmux/plugins/tmux-sensible"
"tmux/tmux-mode-indicator:config/tmux/plugins/tmux-mode-indicator"
"tmux/tmux-yank:config/tmux/plugins/tmux-yank"
":config/tmux/plugins/tmux-fzf-url"
"nvim-kickstart:config/nvim-kickstart"
"asdf:local/bin/asdf"
"asdf:local/asdf"
"dotbot-asdf:tools/dotbot-asdf"
"dotbot-pip:tools/dotbot-pip"
"dotbot-brew:tools/dotbot-brew"
) )
for folder in "${folders[@]}"; do for entry in "${old_submodules[@]}"; do
[ -d "$folder" ] \ name="${entry%%:*}"
&& rm -rf "$folder" \ path="${entry#*:}"
&& msgr run_done "Removed old submodule $folder" remove_old_submodule "$name" "$path"
done done