Felipe97/llama-cpp-compiled
01.2k
1#!/usr/bin/env bash2 3# initialize a new worktree from a branch name:4#5# - creates a new branch from current HEAD6# - creates a new worktree in a parent folder, suffixed with the branch name7#8# sample usage:9# ./scripts/wc2wt.sh gg/new-feature-foo-bar10# ./scripts/wc2wt.sh gg/new-feature-foo-bar opencode11# ./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 117}18 19# check we are in the right directory20if [[ ! -f "scripts/wc2wt.sh" ]]; then21 echo "error: this script must be run from the root of the repository"22 exit 123fi24 25if [[ $# -lt 1 || $# -gt 2 ]]; then26 usage27fi28 29BRANCH=$130 31if [[ -z "$BRANCH" ]]; then32 echo "error: branch name must not be empty"33 exit 134fi35 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" HEAD41 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 worktree50if [[ -f "$og_path/.pi/SYSTEM.md" && ! -f ".pi/SYSTEM.md" ]]; then51 mkdir -p .pi52 ln -sfn "$og_path/.pi/SYSTEM.md" .pi/SYSTEM.md53fi54 55if [[ $# -eq 2 ]]; then56 echo "executing: $2"57 eval "$2"58fi59 