oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#!/bin/sh
2# The release scripts never remove a worktree they didn't make (Astra's
3# Task 16 finding 1): in a disposable repository, a dirty worktree already
4# at the old fixed path survives a failed run and a good one; a run's own
5# worktree goes; a failed add leaves nothing behind.
6set -eu
7here=$(cd "$(dirname "$0")" && pwd)
8scratch=$(mktemp -d "${TMPDIR:-/tmp}/base-wt-test.XXXXXX")
9trap 'rm -rf "$scratch"' EXIT
10repo=$scratch/repo
11git init -q "$repo"
12git -C "$repo" -c user.name=t -c user.email=t@x commit -q --allow-empty -m one
13commit=$(git -C "$repo" rev-parse HEAD)
14# Someone's worktree at the path the old script used, with unsaved work.
15theirs=$scratch/base-tf-1
16git -C "$repo" worktree add -q --detach "$theirs" "$commit"
17echo unsaved > "$theirs/unsaved.txt"
18fail() { echo "worktree-lib_test: $*" >&2; exit 1; }
19
20# A failed run: the add fails (no such commit); cleanup removes nothing of theirs.
21(
22 export TMPDIR=$scratch
23 . "$here/worktree-lib.sh"
24 if own_worktree_add "$repo" deadbeefdeadbeef base-tf-1 2>/dev/null; then exit 3; fi
25 own_worktree_cleanup "$repo"
26 [ ! -e "$OWN_WT" ] || exit 4
27) || fail "a failed add left something behind (status $?)"
28[ -f "$theirs/unsaved.txt" ] || fail "a failed run deleted an existing worktree"
29git -C "$repo" worktree list | grep -q "$(cd "$theirs" && pwd -P)" || fail "a failed run unregistered an existing worktree"
30
31# A good run: its own worktree, somewhere new, removed at the end; theirs stays.
32mine=$(
33 export TMPDIR=$scratch
34 . "$here/worktree-lib.sh"
35 own_worktree_add "$repo" "$commit" base-tf-1
36 [ "$OWN_WT" != "$theirs" ] || exit 5
37 [ -f "$OWN_WT/.git" ] || exit 6
38 echo "$OWN_WT"
39 own_worktree_cleanup "$repo"
40) || fail "a good run failed"
41[ ! -e "$mine" ] || fail "a run's own worktree was left behind"
42[ -f "$theirs/unsaved.txt" ] || fail "a good run deleted an existing worktree"
43echo "worktree-lib_test: ok"
44