From 5a8b5ffd21ced4899ac9d8bdbd4b64911dfa44f7 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 31 Mar 2022 16:00:47 +0200 Subject: [PATCH] git:checkout-worktree: Use `mktemp` template Use a template that directly includes the repository name and the branch checked out. This makes finding and deleting the worktree directory if anything goes wrong a lot easier. Checkout the worktree directly in the temporary directory. With that `TEMP_DIR` becomes obsolete. --- .config/zsh/autoload/git/git-checkout-worktree | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.config/zsh/autoload/git/git-checkout-worktree b/.config/zsh/autoload/git/git-checkout-worktree index c37a0e6..3c11651 100755 --- a/.config/zsh/autoload/git/git-checkout-worktree +++ b/.config/zsh/autoload/git/git-checkout-worktree @@ -11,10 +11,9 @@ # TODO: If any conflicts arise, all further shells should be interactive instead # of looping forever. -local GIT_ROOT TEMP_DIR REPO_DIR -GIT_ROOT="${$(git rev-parse --show-toplevel):t}" || return -TEMP_DIR="$(mktemp -d)" -REPO_DIR="$TEMP_DIR/$GIT_ROOT" +local REPO_NAME REPO_DIR +REPO_NAME="${$(git rev-parse --show-toplevel):t}" || return +REPO_DIR="$(mktemp -d -p "" "worktree.XXX.$REPO_NAME.$1")" git worktree add "$REPO_DIR" "$1" [[ -e "$REPO_DIR" ]] || return 1 @@ -37,5 +36,4 @@ until [[ ! -e "$REPO_DIR" ]] || git worktree remove "$REPO_DIR"; do done git worktree prune -command rm -rf "$TEMP_DIR" return $errc