From 399b571e8553de174974016592c21d2a090c3ab0 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 31 Mar 2022 17:11:59 +0200 Subject: [PATCH] git:checkout-worktree: Refactor into one loop --- .config/zsh/autoload/git/git-checkout-worktree | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/.config/zsh/autoload/git/git-checkout-worktree b/.config/zsh/autoload/git/git-checkout-worktree index b4bfdd7..41605fc 100755 --- a/.config/zsh/autoload/git/git-checkout-worktree +++ b/.config/zsh/autoload/git/git-checkout-worktree @@ -24,25 +24,18 @@ trap ' ' INT QUIT TERM EXIT git worktree add "$WORKTREE_PATH" "$1" - pushd -q "$WORKTREE_PATH" -# Start subshell -"$SHELL" && errc=$? || errc=$? - -# Cleanup when exiting -popd -q || true - -# Restart the subshell until every issue is resolved and the worktree is -# removed -until [[ ! -e "$WORKTREE_PATH" ]] || git worktree remove "$WORKTREE_PATH"; do - pushd -q "$WORKTREE_PATH" +# Restart the shell until every the worktree is removed +while [[ -e "$WORKTREE_PATH" ]]; do "$SHELL" && errc=$? || errc=$? - popd -q || true + git worktree remove "$WORKTREE_PATH" || true done # Reset traps trap '-' INT QUIT TERM EXIT +popd -q || true + git worktree prune return $errc