[odrbin] git-wtclone
This commit is contained in:
parent
10ed0b50a2
commit
6e726c78d4
23
.local/odrbin/git-wtclone
Executable file
23
.local/odrbin/git-wtclone
Executable 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
|
Loading…
Reference in a new issue