Skip to content

fix(hooks): compare repositories, not containment, for the sibling exemption - #16

Merged
Ardnived merged 1 commit into
mainfrom
claude/fix-sibling-repo-exemption
Sep 1, 2026
Merged

Ardnived merged 1 commit into
mainfrom
claude/fix-sibling-repo-exemption

Conversation

@Ardnived

@Ardnived Ardnived commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The sibling-repo exemption in block-wrong-bash compared directory containment, which inverts in a multi-root workspace session — every sibling repo read as "inside this worktree" and both git rules fired on the cross-repo work the exemption exists to allow
  • Now compares repositories: resolve the target's git top-level and the session's, exempt when they differ

Changes

  • workflow/hooks/block-wrong-bash.mjs — gitTopLevel() helper; targetsSiblingRepo() rewritten, with the failure mode documented in place so it is not re-simplified back

Test results

  • node --check clean
  • Exercised against all three session shapes, 5/5 as intended:
Session root Command Verdict
workspace (non-git) cd <sibling> && git status ALLOW
workspace (non-git) git -C <sibling> status ALLOW
inside a repo cd <sibling> && git status ALLOW
inside a repo git -C <same-repo>/docs status DENY
inside a repo cd docs && git log DENY

Notes for reviewer

Found by the subagent doing the SahajCloud rules migration — it could not run git in a sibling repo at all and had to work around it with env -C <repo> git …, which matches neither regex. That workaround is worth knowing about independently: it is the clean way to run git in another repo without tripping either rule.

Two edge cases are now explicit rather than accidental: a session root that is not a repository (every target is a sibling — the workspace case) and a target outside any repository (the rules have nothing to say about it).

…emption

The sibling-repo exemption inverted in exactly the session shape it exists to
serve. worktreeRoot() falls back to the project dir when `git rev-parse`
fails, so a session rooted at the multi-root workspace folder — which is not
itself a repository — takes ROOT to be that folder. Every sibling checkout
then sits *under* ROOT, the containment test read each one as "inside this
worktree", and both git rules fired on precisely the cross-repo work the
exemption was written to allow. A subagent doing the rules migration hit this
and had to route every command through `env -C <repo> git …` to get anything
done.

Compare repositories instead: resolve the target's own git top-level and the
session's, and exempt when they differ. Two cases fall out cleanly — a session
root that is not a repository has no "this repo" for the rules to be about, so
everything is a sibling; and a path outside any repository is nothing the rules
have an opinion on.

Verified against all three session shapes: from the workspace root both
`cd <sibling> && git` and `git -C <sibling>` now pass, while same-repo `git -C`
and `cd <subdir> && git` still deny from inside a repo.

Co-Authored-By: Claude Opus 5 <[email protected]>
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.

1 participant