From f7bc9a9e788151a92984b9f843416b53bb3337ff Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Sun, 12 Jul 2026 17:42:23 -0500 Subject: [PATCH] Test worktree guard fix; make sync-wiring test robust to nested make Add tests/updates for pgxntool commit 864a4f7 (repo-root guard now works in a git worktree via `git rev-parse --git-dir`): - setup.sh / pgxntool-sync.sh / update-setup-files.sh no longer reject a worktree, where `.git` is a file rather than a directory New regression test in update-setup-files.bats: run the script from inside a linked worktree and confirm it gets past the repo-root guard. Also fix the sync-target wiring test: it matched all of `make -n` output, which failed under `make test-all` because the nested make prints "Entering/Leaving directory" bookkeeping. Grep the pgxntool-sync.sh recipe line and match that exactly instead. Co-Authored-By: Claude Opus 4.8 (1M context) --- test/standard/pgxntool-sync.bats | 21 +++++++++++++----- test/standard/update-setup-files.bats | 32 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/test/standard/pgxntool-sync.bats b/test/standard/pgxntool-sync.bats index 858515a..1df7794 100644 --- a/test/standard/pgxntool-sync.bats +++ b/test/standard/pgxntool-sync.bats @@ -165,23 +165,32 @@ setup() { @test "make sync targets wire to the expected repo and ref" { local upstream="https://github.com/Postgres-Extensions/pgxntool.git" - # Each target prints exactly one command; match it in full. The bare target - # passes no args (the script supplies the default repo/ref itself). + # Match the full script-invocation line for each target. We pull that line out + # of `make -n` with grep rather than matching all of $output: when the suite + # runs under `make test-all`, the nested make also prints "Entering/Leaving + # directory" bookkeeping, which is noise for this check. Only the recipe line + # contains "pgxntool-sync.sh", so grep isolates it exactly. + local cmd + run make -n pgxntool-sync assert_success - [ "$output" = "pgxntool/pgxntool-sync.sh" ] + cmd=$(printf '%s\n' "$output" | grep 'pgxntool-sync\.sh') + [ "$cmd" = "pgxntool/pgxntool-sync.sh" ] run make -n pgxntool-sync-master assert_success - [ "$output" = "pgxntool/pgxntool-sync.sh $upstream master" ] + cmd=$(printf '%s\n' "$output" | grep 'pgxntool-sync\.sh') + [ "$cmd" = "pgxntool/pgxntool-sync.sh $upstream master" ] run make -n pgxntool-sync-local assert_success - [ "$output" = "pgxntool/pgxntool-sync.sh ../pgxntool release" ] + cmd=$(printf '%s\n' "$output" | grep 'pgxntool-sync\.sh') + [ "$cmd" = "pgxntool/pgxntool-sync.sh ../pgxntool release" ] run make -n pgxntool-sync-local-master assert_success - [ "$output" = "pgxntool/pgxntool-sync.sh ../pgxntool master" ] + cmd=$(printf '%s\n' "$output" | grep 'pgxntool-sync\.sh') + [ "$cmd" = "pgxntool/pgxntool-sync.sh ../pgxntool master" ] # The script's built-in default (used by bare `pgxntool-sync`) must be the # canonical repo on the release tag, not the old decibel remote. diff --git a/test/standard/update-setup-files.bats b/test/standard/update-setup-files.bats index b8e50b6..ff541f1 100644 --- a/test/standard/update-setup-files.bats +++ b/test/standard/update-setup-files.bats @@ -225,4 +225,36 @@ setup() { [ -L test/pgxntool ] } +# ============================================================================= +# Regression (issue #38): must work inside a git worktree +# ============================================================================= +# In a linked worktree, `.git` is a file (a gitdir: pointer), not a directory. +# The old `[ -d .git ]` root guard rejected valid worktrees with "Not in a git +# repository." Run the script from inside a worktree of the test repo and +# confirm it gets past the guard and does its normal work. + +@test "runs inside a git worktree where .git is a file" { + local old_commit + old_commit=$(git log -1 --format=%H -- pgxntool/) + + local wt="$TEST_DIR/worktree-38" + # Idempotent: clear any leftover from a prior interrupted run before adding. + rm -rf "$wt" + git worktree prune + run git worktree add --quiet "$wt" HEAD + assert_success + + [ -f "$wt/.git" ] # sanity: worktree marker really is a file, not a directory + + cd "$wt" + run pgxntool/update-setup-files.sh "$old_commit" + # Remove the worktree before asserting so a failure can't leave it registered. + cd "$TEST_REPO" + git worktree remove --force "$wt" + + assert_success + # Reached the real work instead of dying on the repo-root guard. + assert_contains "$output" "Checking setup files for updates" +} + # vi: expandtab sw=2 ts=2