[odrbin] git-wtclone: set worktree manually

This commit is contained in:
odrling 2023-11-25 23:42:44 +01:00
parent 6a86a1363a
commit f4c1de11ff
No known key found for this signature in database
GPG key ID: E24CA7508C27AF5B

View file

@ -4,7 +4,7 @@ name="$(basename "$url" .git)"
worktree="$2"
[ -z "$worktree" ] && worktree="$name"
[ -z "$GITDIRS" ] && GITDIRS="$HOME/git/.gitdirs"
mkdir -p $GITDIRS
mkdir -p "$GITDIRS"
if [ -d "$GITDIRS/$name.git" ]; then
GIT_DIR="$GITDIRS/$name.git"
@ -17,8 +17,8 @@ fi
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"
mkdir -p "$GIT_WORK_TREE"
echo "gitdir: $GIT_DIR" > "$GIT_WORK_TREE/.git"
git -C "GIT_WORK_TREE" fetch
git -C "$GIT_WORK_TREE" checkout "$GIT_WORK_TREE"
fi