test-pairing.sh
#!/bin/bash
## Pairing: `patchette pair` records a subject repo's patches dir in the
## common git dir's `patchette` file, letting verbs run flagless from inside
## any of the repo's worktrees. Explicit flags win per value; removing the
## file un-pairs cleanly.
set -euo pipefail
cd "$(dirname "$0")"
source ./lib.sh
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
make_corpus "$work/corpus"
source "$work/corpus/FACTS"
dev="$work/corpus/dev"
## Run patchette with a given cwd (pairing resolution is cwd-sensitive).
##
## - @param $1 directory to run in
## - @param $@ patchette args
patchette_in() {
local d=$1
shift
(cd "$d" && "$PATCHETTE" "$@")
}
EXPECT refusal "flagless verbs in an unpaired repo refuse helpfully" "not paired" -- \
patchette_in "$dev" verify
EXPECT refusal "pair refuses a nonexistent patches dir" "no such directory" -- \
patchette_in "$dev" pair ../no-such-dir
EXPECT success "and creates nothing" -- \
test ! -e "$work/corpus/no-such-dir"
"$PATCHETTE" export --subject="$dev" --patches="$work/explicit" "$base" topic/fancy docs-polish >/dev/null
mkdir "$work/corpus/patches"
patchette_in "$dev" pair ../patches >/dev/null
EXPECT success "pair writes git-config format readable by git config" -- \
test "$(git config --file "$dev/.git/patchette" --get patchette.patches)" = "../patches"
EXPECT success "flagless pair reports the pairing" -- \
bash -c 'cd "$1" && "$2" pair | grep -q "patches dir"' -- "$dev" "$PATCHETTE"
patchette_in "$dev" export "$base" topic/fancy docs-polish >/dev/null
EXPECT success "flagless export inside the paired repo matches an explicit export byte-for-byte" -- \
diff -r "$work/explicit" "$work/corpus/patches"
EXPECT success "flagless verify inside the paired repo passes" -- \
patchette_in "$dev" verify
EXPECT success "flagless verify works from a subdirectory too" -- \
patchette_in "$dev/widgets" verify
# Pairing is repo-wide, not per-worktree: it rides the common git dir.
git -C "$dev" worktree add -q "$work/dev-wt" topic/fancy
EXPECT success "a linked worktree sees the pairing made in the main worktree" -- \
patchette_in "$work/dev-wt" verify
patchette_in "$work/dev-wt" pair "$work/explicit" >/dev/null
EXPECT success "pairing from a linked worktree rewrites the one shared pairing" -- \
bash -c 'cd "$1" && "$2" pair | grep -q "explicit"' -- "$dev" "$PATCHETTE"
patchette_in "$dev" pair ../patches >/dev/null
# Explicit flags win, per value: aim --patches at a tampered copy while the
# subject still comes from the pairing, and the refusal proves what was read.
cp -r "$work/explicit" "$work/tampered"
sed -i 's/> The hum is load-bearing./> The hum is decorative./' "$work/tampered/topic¦fancy/teach-gizmo-to-hum.patch"
EXPECT refusal "an explicit flag wins over the pairing, per value" "MISMATCH" -- \
patchette_in "$dev" verify --patches="$work/tampered"
# The recreate journey, flagless: pair a fresh clone, import inside it.
git clone -q "$work/corpus/upstream" "$work/fresh"
patchette_in "$work/fresh" pair "$work/explicit" >/dev/null
patchette_in "$work/fresh" import >/dev/null
EXPECT equal "flagless import inside a paired fresh clone reproduces tips" -- \
"$(git -C "$work/fresh" rev-parse refs/heads/topic/fancy)" "$tip_topic_fancy"
rm "$dev/.git/patchette"
EXPECT refusal "removing the pairing file un-pairs cleanly" "not paired" -- \
patchette_in "$dev" verify
exit "$RESULT"
tests/test-pairing.sh · 3.3 KiB · bd494f7d30