From 71450ad133a581f4ba9c081f7ed409858038b1d0 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 31 Mar 2022 17:28:05 +0200 Subject: [PATCH] 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. --- .config/zsh/autoload/git/git-checkout-worktree | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.config/zsh/autoload/git/git-checkout-worktree b/.config/zsh/autoload/git/git-checkout-worktree index 41605fc..315012d 100755 --- a/.config/zsh/autoload/git/git-checkout-worktree +++ b/.config/zsh/autoload/git/git-checkout-worktree @@ -7,9 +7,8 @@ # (e.g. stashing). Finally the temporary directory is deleted. # # Instead of dropping in an interactive shell, the commands to execute can be -# passed via stdin. -# TODO: If any conflicts arise, all further shells should be interactive instead -# of looping forever. +# passed via stdin. If any conflicts arise, all further shells are interactive. +# TODO: Override with flag that just `stash -u` emulate -L zsh -o err_return -o no_unset @@ -26,15 +25,16 @@ trap ' git worktree add "$WORKTREE_PATH" "$1" pushd -q "$WORKTREE_PATH" -# Restart the shell until every the worktree is removed -while [[ -e "$WORKTREE_PATH" ]]; do - "$SHELL" && errc=$? || errc=$? - git worktree remove "$WORKTREE_PATH" || true +"$SHELL" && errc=$? || errc=$? + +# Restart the shell (forcefully interactive) until the worktree is removed +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 -# Reset traps +# Reset traps and PWD trap '-' INT QUIT TERM EXIT - popd -q || true git worktree prune