char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
1a946ec74
char/aliceai-t5-moe
1#!/usr/bin/env bash 2 3# initialize a new worktree from a PR number: 4# 5# - creates a new remote using the fork's clone URL 6# - creates a local branch tracking the remote branch 7# - creates a new worktree in a parent folder, suffixed with "-pr-$PR" 8# 9# sample usage: 10# ./scripts/pr2wt.sh 12345 11# ./scripts/pr2wt.sh 12345 opencode 12# ./scripts/pr2wt.sh 12345 "cmake -B build && cmake --build build" 13# ./scripts/pr2wt.sh 12345 "bash -l" 14 15function usage () { 16echo "usage: $ 0 <pr_number> [cmd]" 17exit 1 18} 19 20# check we are in the right directory 21if [[ ! -f"scripts/pr2wt.sh" ]];then 22echo "error: this script must be run from the root of the repository" 23exit 1 24fi 25 26if [[$ # -lt 1 ||$ # -gt 2 ]];then 27usage 28fi 29 30PR =$ 1 31[[" $ PR " =~ ^[0-9]+$ ]] || {echo "error: PR number must be numeric" ;exit 1; } 32 33url_origin =$( git config --get remote.upstream.url 2 > /dev/null) || \ 34url_origin =$( git config --get remote.origin.url) || { 35echo "error: no remote named 'upstream' or 'origin' in this repository" 36exit 1 37} 38 39# Extract org/repo from either https or ssh format. 40if [[$ url_origin =~ ^git@ ]];then 41org_repo =$( echo $ url_origin | cut -d: -f2 ) 42else 43org_repo =$( echo $ url_origin | cut -d/ -f4- ) 44fi 45org_repo =${ org_repo %.git} 46 47echo "org/repo: $ org_repo " 48 49meta =$( curl -sSLf -H "Accept: application/vnd.github+json" "https://api.github.com/repos/ $ org_repo /pulls/ $ PR " ) 50 51if [[$ url_origin =~ ^git@ ]];then 52url_remote =$( echo " $ meta " | jq -r '.head.repo.ssh_url' ) 53else 54url_remote =$( echo " $ meta " | jq -r '.head.repo.clone_url' ) 55fi 56head_ref =$( echo " $ meta " | jq -r '.head.ref' ) 57 58echo "url: $ url_remote " 59echo "head_ref: $ head_ref " 60 61url_remote_cur =$( git config --get "remote.pr/ $ PR .url" 2 > /dev/null || true ) 62 63if [[" $ url_remote_cur " !=" $ url_remote " ]];then 64git remote rm pr/$ PR 2 > /dev/null 65git remote add pr/$ PR " $ url_remote " 66fi 67 68git fetch"pr/ $ PR " " $ head_ref " 69 70dir =$( basename $( pwd )) 71 72git branch-D pr/$ PR 2 > /dev/null 73git worktree add-b pr/$ PR ../$ dir -pr-$ PR pr/$ PR /$ head_ref 2 > /dev/null 74 75og_path =$( pwd ) 76wt_path =$( cd ../ $ dir -pr- $ PR && pwd ) 77 78echo "git worktree created in $ wt_path " 79 80cd $ wt_path 81 82# pi agent setup in the worktree 83if [[ -f" $ og_path /.pi/SYSTEM.md" && ! -f".pi/SYSTEM.md" ]];then 84mkdir -p .pi 85ln -sfn " $ og_path /.pi/SYSTEM.md" .pi/SYSTEM.md 86fi 87 88git branch--set-upstream-to=pr/ $ PR / $ head_ref 89git pull--ff-only || { 90echo "error: failed to pull pr/ $ PR " 91exit 1 92} 93 94if [[$ # -eq 2 ]];then 95echo "executing: $ 2 " 96eval " $ 2 " 97fi