#!/usr/bin/env bash # Smoke-tests wt-new.sh / wt-clean.sh against a local file:// origin. set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" WT_NEW="$here/wt-new.sh" WT_CLEAN="$here/wt-clean.sh" PASS=0 FAIL=0 check() { if [ "$2" = "$3" ]; then echo "PASS: $1 ($3)"; PASS=$((PASS+1)); else echo "FAIL: $1 — expected '$2' got '$3'"; FAIL=$((FAIL+1)); fi; } T="$(mktemp -d)" trap 'rm -rf "$T"' EXIT git init -q --bare "$T/origin.git" git clone -q "$T/origin.git" "$T/primary" git -C "$T/primary" config user.email t@t.io git -C "$T/primary" config user.name tester echo seed > "$T/primary/README.md" git -C "$T/primary" add -A git -C "$T/primary" commit -qm seed git -C "$T/primary" branch -M main git -C "$T/primary" push -q origin main run() { ( cd "$T/primary" && "$@" ); } target="$T/primary-worktree-thing-one" echo "--- wt-new rejects a non-conventional branch name ---" set +e; run bash "$WT_NEW" my-thing >/dev/null 2>&1; rc=$?; set -e check "bad-prefix rejected" "yes" "$( [ "$rc" -ne 0 ] && echo yes || echo no )" echo "--- wt-new creates branch + sibling worktree ---" out="$(run bash "$WT_NEW" feat/thing-one 2>/dev/null)" check "prints target path" "$target" "$out" check "worktree dir exists" "yes" "$( [ -d "$target" ] && echo yes || echo no )" check "worktree on the new branch" "feat/thing-one" "$(git -C "$target" rev-parse --abbrev-ref HEAD)" echo "--- wt-new refuses to clobber an existing branch ---" set +e; run bash "$WT_NEW" feat/thing-one >/dev/null 2>&1; rc=$?; set -e check "duplicate rejected" "yes" "$( [ "$rc" -ne 0 ] && echo yes || echo no )" echo "--- wt-clean removes a MERGED worktree (and keeps an unmerged one) ---" # thing-one: make it merged into origin/main (push its tip to main). git -C "$target" commit -q --allow-empty -m "thing-one work" git -C "$target" push -q origin HEAD:main # thing-two: a second worktree that is NOT merged. run bash "$WT_NEW" feat/thing-two >/dev/null 2>&1 target2="$T/primary-worktree-thing-two" git -C "$target2" commit -q --allow-empty -m "thing-two work (unmerged)" run bash "$WT_CLEAN" >/dev/null 2>&1 check "merged worktree removed" "no" "$( [ -d "$target" ] && echo yes || echo no )" check "unmerged worktree kept" "yes" "$( [ -d "$target2" ] && echo yes || echo no )" echo echo "==== $PASS passed, $FAIL failed ====" [ "$FAIL" -eq 0 ]