patchette

test-roundtrip.sh

#!/bin/bash
## Roundtrip, for both sigil dialects: export is regeneration-stable,
## verify passes, and import into a fresh clone of upstream reproduces the
## exact branch tips, fsck-clean.
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"

for sigil in quote tab; do
	p="$work/$sigil"

	"$PATCHETTE" export "--sigil=$sigil" "$work/corpus/dev" "$p/patches" "$base" topic/fancy docs-polish >/dev/null
	"$PATCHETTE" export "--sigil=$sigil" "$work/corpus/dev" "$p/again" "$base" topic/fancy docs-polish >/dev/null
	EXPECT success "$sigil: export is regeneration-stable (two runs byte-identical)" -- \
		diff -r "$p/patches" "$p/again"

	# Guard the guard: confirm the flag actually switched the emitted framing,
	# or this loop would just test the quote dialect twice.
	sample="$p/patches/topic¦fancy/teach-gizmo-to-hum.patch"
	case $sigil in
	quote) want=$'> The hum is load-bearing.' ;;
	tab) want=$'\tThe hum is load-bearing.' ;;
	esac
	EXPECT success "$sigil: emitted message framing matches the dialect" -- \
		grep -qxF "$want" "$sample"

	EXPECT success "$sigil: verify passes on a fresh export" -- \
		"$PATCHETTE" verify "$work/corpus/dev" "$p/patches"

	# The recreate story: upstream has none of our branches; the patches repo
	# alone must bring them back, byte-exact.
	git clone -q "$work/corpus/upstream" "$p/fresh"
	"$PATCHETTE" import "$p/fresh" "$p/patches" >/dev/null
	EXPECT equal "$sigil: import reproduces the exact topic/fancy tip" -- \
		"$(git -C "$p/fresh" rev-parse refs/heads/topic/fancy)" "$tip_topic_fancy"
	EXPECT equal "$sigil: import reproduces the exact docs-polish tip" -- \
		"$(git -C "$p/fresh" rev-parse refs/heads/docs-polish)" "$tip_docs_polish"

	EXPECT success "$sigil: fsck --strict clean on the replayed repo" -- \
		git -C "$p/fresh" fsck --strict
done

exit "$RESULT"

tests/test-roundtrip.sh · 1.9 KiB · f61b01a155