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.
This commit is contained in:
2022-03-31 16:00:47 +02:00
parent 976d3f9000
commit 5a8b5ffd21

View File

@@ -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