Make worktree rm actually work in the presence of submodules
Also adds the `--force` option to remove a worktree with unstaged changes.
This commit is contained in:
@@ -102,7 +102,22 @@ Manage git worktrees by branch name."
|
|||||||
fi
|
fi
|
||||||
local -a rm_args=()
|
local -a rm_args=()
|
||||||
(( force )) && rm_args+=(--force)
|
(( 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
|
failed=1
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user