[odrbin] git-wtclone

This commit is contained in:
odrling 2023-11-25 00:34:14 +01:00
parent 10ed0b50a2
commit 6e726c78d4
No known key found for this signature in database
GPG key ID: E24CA7508C27AF5B

23
.local/odrbin/git-wtclone Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh
url="$1"
name="$(basename "$url" .git)"
worktree="$2"
[ -z "$worktree" ] && worktree="$name"
[ -z "$GITDIRS" ] && GITDIRS="$HOME/gitdirs"
if [ -d "$GITDIRS/$name.git" ]; then
GIT_DIR="$GITDIRS/$name.git"
else
GIT_DIR="$GITDIRS/$name"
fi
[ -z "$worktree" ] && echo "usage: $0 NAME WORKTREE" && exit 1
GIT_WORK_TREE="$(realpath "$worktree")"
if ! git clone --separate-git-dir "$GIT_DIR" "$url" "$GIT_WORK_TREE"; then
export GIT_DIR
git remote set-url origin "$url"
git fetch origin
git worktree add -f "$GIT_WORK_TREE"
fi