Skip to content

Commit 27aef3d

Browse files
authored
scripts : add wc2wt.sh - create worktree from current HEAD (ggml-org#22513)
* scripts : add wc2wt.sh - create worktree from current HEAD Add a script to create a git worktree on a new branch from the current HEAD. Similar to pr2wt.sh but for local development branches instead of PRs. Usage: ./scripts/wc2wt.sh gg/new-feature ./scripts/wc2wt.sh gg/new-feature "bash -l" Assisted-by: llama.cpp:local pi * cont : no need to try to delete the branch
1 parent 4515559 commit 27aef3d

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

scripts/wc2wt.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
# initialize a new worktree from a branch name:
4+
#
5+
# - creates a new branch from current HEAD
6+
# - creates a new worktree in a parent folder, suffixed with the branch name
7+
#
8+
# sample usage:
9+
# ./scripts/wc2wt.sh gg/new-feature-foo-bar
10+
# ./scripts/wc2wt.sh gg/new-feature-foo-bar opencode
11+
# ./scripts/wc2wt.sh gg/new-feature-foo-bar "cmake -B build && cmake --build build"
12+
# ./scripts/wc2wt.sh gg/new-feature-foo-bar "bash -l"
13+
14+
function usage() {
15+
echo "usage: $0 <branch_name> [cmd]"
16+
exit 1
17+
}
18+
19+
# check we are in the right directory
20+
if [[ ! -f "scripts/wc2wt.sh" ]]; then
21+
echo "error: this script must be run from the root of the repository"
22+
exit 1
23+
fi
24+
25+
if [[ $# -lt 1 || $# -gt 2 ]]; then
26+
usage
27+
fi
28+
29+
BRANCH=$1
30+
31+
if [[ -z "$BRANCH" ]]; then
32+
echo "error: branch name must not be empty"
33+
exit 1
34+
fi
35+
36+
dir=$(basename $(pwd))
37+
# sanitize branch name for directory name (replace / with -)
38+
dir_suffix=$(echo "$BRANCH" | tr '/' '-')
39+
40+
git worktree add -b "$BRANCH" "../$dir-$dir_suffix" HEAD
41+
42+
og_path=$(pwd)
43+
wt_path=$(cd "../$dir-$dir_suffix" && pwd)
44+
45+
echo "git worktree created in $wt_path"
46+
47+
cd "$wt_path"
48+
49+
# pi agent setup in the worktree
50+
if [[ -f "$og_path/.pi/SYSTEM.md" && ! -f ".pi/SYSTEM.md" ]]; then
51+
mkdir -p .pi
52+
ln -sfn "$og_path/.pi/SYSTEM.md" .pi/SYSTEM.md
53+
fi
54+
55+
if [[ $# -eq 2 ]]; then
56+
echo "executing: $2"
57+
eval "$2"
58+
fi

0 commit comments

Comments
 (0)