diff --git a/worktree/worktree.plugin.zsh b/worktree/worktree.plugin.zsh index 22d31ab..923e22d 100644 --- a/worktree/worktree.plugin.zsh +++ b/worktree/worktree.plugin.zsh @@ -102,7 +102,22 @@ Manage git worktrees by branch name." fi local -a rm_args=() (( force )) && rm_args+=(--force) - if ! git worktree remove "${rm_args[@]}" "$wt_path"; then + local err + if err=$(git worktree remove "${rm_args[@]}" "$wt_path" 2>&1); then + : + elif [[ "$err" == *"working trees containing submodules"* ]]; then + if (( ! force )) && \ + [[ -n "$(git -C "$wt_path" status --porcelain --ignore-submodules=all 2>/dev/null)" ]]; then + print -P "%F{red}error:%f worktree has uncommitted changes (use --force): $wt_path" + failed=1 + continue + fi + if ! rm -rf "$wt_path" || ! git worktree prune; then + failed=1 + continue + fi + else + print -- "$err" >&2 failed=1 continue fi