git:checkout-worktree: Refactor into one loop

This commit is contained in:
2022-03-31 17:11:59 +02:00
parent a60c955d3d
commit 399b571e85

View File

@@ -24,25 +24,18 @@ trap '
' INT QUIT TERM EXIT ' INT QUIT TERM EXIT
git worktree add "$WORKTREE_PATH" "$1" git worktree add "$WORKTREE_PATH" "$1"
pushd -q "$WORKTREE_PATH" pushd -q "$WORKTREE_PATH"
# Start subshell # Restart the shell until every the worktree is removed
"$SHELL" && errc=$? || errc=$? while [[ -e "$WORKTREE_PATH" ]]; do
# 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"
"$SHELL" && errc=$? || errc=$? "$SHELL" && errc=$? || errc=$?
popd -q || true git worktree remove "$WORKTREE_PATH" || true
done done
# Reset traps # Reset traps
trap '-' INT QUIT TERM EXIT trap '-' INT QUIT TERM EXIT
popd -q || true
git worktree prune git worktree prune
return $errc return $errc