Skip to content

test(guards): resolve the repo root without git rev-parse under the pre-commit hook - #1343

Merged
mforce merged 2 commits into
mainfrom
fix/1342-repo-root
Oct 21, 2026
Merged

mforce merged 2 commits into
mainfrom
fix/1342-repo-root

Conversation

@mforce

@mforce mforce commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Closes #1342

Why

In a linked worktree, the pre-commit hook exports GIT_DIR without GIT_WORK_TREE. TenancyDocsFreshnessTests.RepoRoot() ran git rev-parse --show-toplevel from the test's bin folder, so git returned that bin folder. FileSizeLimitTests and SpellingScannerRatchetTests then threw DirectoryNotFoundException, and commits in worktrees fell back to --no-verify.

The issue says all three tests failed. TenancyDocsFreshnessTests passed. It skips paths that are missing on disk, so it read 0 files and found nothing to flag.

What changed

One test file, tests/Cluckwork.Application.Tests/Documentation/TenancyDocsFreshnessTests.cs:

  • RepoRoot() uses GuardScanner.FindRepoRoot, the same as RenameAccountDocsTests.RepoRoot().
  • The tenancy wording walk fails when it reads 1,000 files or fewer, so a wrong root can no longer pass silently. It read 2,561 on 2026-10-21. The floor assumes a full checkout, as CI uses; a sparse checkout below 1,000 files would fail it.
  • The new TenancyDocsFreshnessRepoRootTests sets GIT_DIR to the checkout's real git dir and asserts that the returned root holds Cluckwork.slnx. The existing RenameAccountDocsRepoRootTests covers only the other helper.

Verification

  • dotnet build Cluckwork.slnx reports 0 warnings. The filtered tests (TenancyDocsFreshness, FileSizeLimitTests, SpellingScannerRatchetTests, RenameAccountDocsRepoRootTests) pass 7/7, both normally and with GIT_DIR set to the worktree's git dir.
  • With the old helper restored and GIT_DIR exported to the worktree's git dir, FileSizeLimitTests and SpellingScannerRatchetTests throw DirectoryNotFoundException under bin/Debug/net10.0/, and the tenancy walk fails with Read only 0 tracked files under .../bin/Debug/net10.0. Before the floor, the tenancy walk passed in this setup.
  • With the old helper restored and no GIT_DIR exported, the new test sets GIT_DIR itself and fails with RepoRoot() returned .../bin/Debug/net10.0.
  • A first version of the new test asserted on the git ls-files output. It stayed green against the old helper, because ls-files lists the whole index even when git takes bin as the work tree. The test now checks the file on disk instead.
  • Both commits went through the pre-commit hook in a linked worktree without --no-verify (Domain 496/496, Application 783/783).

…re-commit hook

TenancyDocsFreshnessTests.RepoRoot() now uses GuardScanner.FindRepoRoot. Under the pre-commit hook in a linked worktree, git exports GIT_DIR without GIT_WORK_TREE, so rev-parse returned the test's bin folder and FileSizeLimitTests and SpellingScannerRatchetTests failed.

Refs #1342
…iles

With a wrong repo root, every tracked path fails File.Exists and is skipped, so the guard passed while reading nothing. It now requires more than 1,000 files read (2,561 measured on 2026-10-21).

Refs #1342
@mforce
mforce merged commit 63378d3 into main Oct 21, 2026
18 checks passed
@mforce
mforce deleted the fix/1342-repo-root branch October 21, 2026 18:57
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.

Pre-commit hook fails three tracked-file guards in linked worktrees

1 participant