git:checkout-worktree: Fix endless loop

Fix endless loop when commands are passed via stdin that result in the
worktree not being removable. Fix by then dropping into an interactive
shell.
This commit is contained in:
2022-03-31 17:28:05 +02:00
parent 399b571e85
commit 71450ad133

View File

@@ -7,9 +7,8 @@
# (e.g. stashing). Finally the temporary directory is deleted. # (e.g. stashing). Finally the temporary directory is deleted.
# #
# Instead of dropping in an interactive shell, the commands to execute can be # Instead of dropping in an interactive shell, the commands to execute can be
# passed via stdin. # passed via stdin. If any conflicts arise, all further shells are interactive.
# TODO: If any conflicts arise, all further shells should be interactive instead # TODO: Override with flag that just `stash -u`
# of looping forever.
emulate -L zsh -o err_return -o no_unset emulate -L zsh -o err_return -o no_unset
@@ -26,15 +25,16 @@ trap '
git worktree add "$WORKTREE_PATH" "$1" git worktree add "$WORKTREE_PATH" "$1"
pushd -q "$WORKTREE_PATH" pushd -q "$WORKTREE_PATH"
# Restart the shell until every the worktree is removed "$SHELL" && errc=$? || errc=$?
while [[ -e "$WORKTREE_PATH" ]]; do
"$SHELL" && errc=$? || errc=$? # Restart the shell (forcefully interactive) until the worktree is removed
git worktree remove "$WORKTREE_PATH" || true until [[ ! -e "$WORKTREE_PATH" ]] || git worktree remove "$WORKTREE_PATH"; do
[[ -t 0 ]] || >&2 printf "Dropping into interactive shell to resolve conflicts\n"
"$SHELL" -i && errc=$? || errc=$?
done done
# Reset traps # Reset traps and PWD
trap '-' INT QUIT TERM EXIT trap '-' INT QUIT TERM EXIT
popd -q || true popd -q || true
git worktree prune git worktree prune