Files
reims-vgpu/scripts/internal/new-worktree.sh
T
Anees Iqbal 28aecd0f04 🎨 Move the development scripts to scripts/internal
scripts/ mixed the one script a person installing reims-ctl runs,
install-ctl.sh, with eight that only developing the project runs: the worktree
and build environment, the GPU locks, the VM boot and tour drivers, the window
walk and the IOSurface qtest. Those move to scripts/internal, so scripts/ holds
what users run. run_vmapple.sh, walk_window_macos.sh and vm_drive.py find the
repository from their own path, one level deeper now; every reference in the
docs, the Makefile, the video crates' tools and the code's comments follows.
2026-10-26 14:08:39 +02:00

39 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# A new worktree whose large tracked files are APFS clones of the main checkout's, so git writes
# only the files that differ. Its builds run with its own CARGO_TARGET_DIR and the environment of
# scripts/internal/dev-env.sh, which builds through kache where it is installed
# (docs/development.md).
#
# scripts/internal/new-worktree.sh PATH BRANCH [START]
#
# BRANCH is a new branch at START (default: the main checkout's HEAD). tests/suite holds 257 of
# the tree's 278 MiB (its expected and generated files), and a plain `git worktree add` writes
# every byte of it again. Here the main checkout's tests/suite is cloned into PATH first (on
# macOS cp -c, which writes nothing until a file changes; on Linux cp --reflink=auto, a copy
# where the filesystem has no reflinks). git then takes each clone that matches START's blob as
# clean and writes the rest, and the clone's files START does not track are removed, so the
# worktree holds START's tree exactly, whatever the main checkout's files are.
#
# The worktree is added from the main checkout: a new worktree takes the sparse-checkout
# settings of the one it is added from.
set -euo pipefail
[[ $# -ge 2 ]] || { echo "usage: scripts/internal/new-worktree.sh PATH BRANCH [START]" >&2; exit 2; }
path=$1 branch=$2
main=$(git worktree list --porcelain | sed -n '1s/^worktree //p')
start=${3:-$(git -C "$main" rev-parse HEAD)}
big=tests/suite
[[ ! -e $path ]] || { echo "new-worktree: $path exists" >&2; exit 1; }
git -C "$main" worktree add -q --no-checkout -b "$branch" "$path" "$start"
path=$(cd "$path" && pwd)
mkdir -p "$path/$(dirname "$big")"
if [[ $(uname) == Darwin ]]; then
cp -c -p -R "$main/$big" "$path/$big"
else
cp -a --reflink=auto "$main/$big" "$path/$big"
fi
git -C "$path" reset -q
git -C "$path" update-index -q --refresh || true
git -C "$path" checkout -q -- .
git -C "$path" clean -q -f -d -x -- "$big"
echo "new-worktree: $path on $branch at $(git -C "$path" rev-parse --short HEAD)"