char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Georgi Gerganovscripts : allow wc2wt with an existing branch (#23189)c3f95c1f0

char/aliceai-t5-moe
1.4 KiB58 linesraw
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
14function usage() {
15    echo "usage: $0 <branch_name> [cmd]"
16    exit 1
17}
18
19# check we are in the right directory
20if [[ ! -f "scripts/wc2wt.sh" ]]; then
21    echo "error: this script must be run from the root of the repository"
22    exit 1
23fi
24
25if [[ $# -lt 1 || $# -gt 2 ]]; then
26    usage
27fi
28
29BRANCH=$1
30
31if [[ -z "$BRANCH" ]]; then
32    echo "error: branch name must not be empty"
33    exit 1
34fi
35
36dir=$(basename $(pwd))
37# sanitize branch name for directory name (replace / with -)
38dir_suffix=$(echo "$BRANCH" | tr '/' '-')
39
40git worktree add "../$dir-$dir_suffix" "$BRANCH" || git worktree add -b "$BRANCH" "../$dir-$dir_suffix" HEAD
41
42og_path=$(pwd)
43wt_path=$(cd "../$dir-$dir_suffix" && pwd)
44
45echo "git worktree created in $wt_path"
46
47cd "$wt_path"
48
49# pi agent setup in the worktree
50if [[ -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
53fi
54
55if [[ $# -eq 2 ]]; then
56    echo "executing: $2"
57    eval "$2"
58fi