Skip to content

Fix repo-root guard to work inside a git worktree#39

Merged
jnasbyupgrade merged 2 commits into
Postgres-Extensions:masterfrom
jnasbyupgrade:fix-38-worktree-guard
Jul 14, 2026
Merged

Fix repo-root guard to work inside a git worktree#39
jnasbyupgrade merged 2 commits into
Postgres-Extensions:masterfrom
jnasbyupgrade:fix-38-worktree-guard

Conversation

@jnasbyupgrade

@jnasbyupgrade jnasbyupgrade commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #38.

setup.sh, pgxntool-sync.sh, and update-setup-files.sh guarded the project root with [ -d .git ]. In a linked git worktree (git worktree add), .git is a file (a gitdir: pointer), not a directory, so the guard failed on a perfectly valid working tree:

  • setup.sh wrongly re-ran git init
  • the sync scripts aborted with ERROR: Not in a git repository.

All three now detect the repo with git rev-parse --git-dir, which works in both a normal clone and a worktree.

Verification

  • Reproduced the failure with the old guard and confirmed the fix passes, running the script from inside a real worktree.
  • Full suite green (212/212) on PG 17.

Related pgxntool-test PR: Postgres-Extensions/pgxntool-test#24

🤖 Generated with Claude Code

setup.sh, pgxntool-sync.sh, and update-setup-files.sh guarded the project root
with `[ -d .git ]`. In a linked git worktree `.git` is a file, not a directory,
so the guard failed: setup.sh wrongly re-ran `git init`, and the sync scripts
aborted with "Not in a git repository." on a perfectly valid working tree. They
now detect the repo with `git rev-parse --git-dir`, which works in both a normal
clone and a worktree.

Fixes Postgres-Extensions#38.

Related changes in pgxntool-test:
- Add a regression test running update-setup-files.sh inside a git worktree

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 355f3df2-34d4-4a74-a394-5f5c73f0f374

📥 Commits

Reviewing files that changed from the base of the PR and between b062fca and b9af993.

📒 Files selected for processing (4)
  • HISTORY.asc
  • pgxntool-sync.sh
  • setup.sh
  • update-setup-files.sh

📝 Walkthrough

Walkthrough

The setup, synchronization, and setup-file update scripts now detect Git repositories with git rev-parse --git-dir instead of requiring .git to be a directory. This allows the scripts to operate correctly in Git worktrees, where .git is a file. The changelog adds a new stable entry documenting these fixes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Postgres-Extensions/pgxntool issue 17 — Covers replacing .git directory checks with worktree-compatible Git repository detection in the same setup scripts.

Poem

A rabbit hops where worktrees grow,
.git is a file, not a folder below.
The scripts now ask Git, “Are we home?”
No false alarms, no need to roam.
Setup syncs with a cheerful glow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: making repo-root checks work in Git worktrees.
Description check ✅ Passed The description accurately describes the worktree guard fix and related script behavior changes.
Linked Issues check ✅ Passed The scripts now use a worktree-safe Git repo check, satisfying the linked issue's requirements.
Out of Scope Changes check ✅ Passed The only extra change is the history note, which is directly related to the fix and not unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jnasbyupgrade jnasbyupgrade merged commit c7928af into Postgres-Extensions:master Jul 14, 2026
2 of 3 checks passed
jnasbyupgrade added a commit to Postgres-Extensions/pgxntool-test that referenced this pull request Jul 14, 2026
…24)

Related pgxntool PR:
Postgres-Extensions/pgxntool#39

Covers the pgxntool fix for the `.git`-in-a-worktree guard (issue #38).

- **New regression test** (`update-setup-files.bats`): runs
`update-setup-files.sh` from inside a linked git worktree (where `.git`
is a file) and confirms it gets past the repo-root guard instead of
dying with "Not in a git repository."
- **Fix flaky wiring test** (`pgxntool-sync.bats`): the sync-target test
matched all of `make -n` output, which failed under `make test-all`
because the nested make prints "Entering/Leaving directory" bookkeeping.
It now greps the `pgxntool-sync.sh` recipe line and matches that exactly
— still pins the full command, but ignores make's chatter.

Full suite green (212/212) on PG 17.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pgxntool-sync.sh / update-setup-files.sh fail inside a git worktree

1 participant