Skip to content

dev-shell-hook: never auto-allow a HEAD off every origin branch - #35

Merged
kixelated merged 1 commit into
mainfrom
dev-shell-origin-guard
Nov 3, 2026
Merged

kixelated merged 1 commit into
mainfrom
dev-shell-origin-guard

Conversation

@kixelated

Copy link
Copy Markdown
Owner

bin/dev-shell-hook (from kixelated/dotfiles#33) auto-approved any checkout whose .envrc, flake.nix, and flake.lock matched origin/HEAD. That included a fork PR head fetched from a contributor remote, as the review in moq-dev/quest#458 pointed out.

The hook now runs direnv allow only when git for-each-ref --contains HEAD refs/remotes/origin/ finds some branch. Otherwise it refuses through the existing refuse() path with one stderr line, "HEAD isn't on any origin branch", and exits 1. Everything else is unchanged: it still compares files against origin/HEAD, never fetches, and adds no owner allowlist or clean-tree check. Checkouts direnv has already approved keep loading after new local commits, because direnv keys approval on the .envrc path and contents, not on HEAD.

The docstring and docs/dev-shell.md describe the new condition.

Tests (python3 -m unittest discover -s tests, 17 pass):

  • A HEAD on a non-default origin branch is allowed.
  • An unpushed local commit is refused.
  • A fork-head checkout, where the commit is fetched from a contributor remote and the reviewed files still match, is refused.

Both refusal tests fail when the guard is disabled.

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

A session rooted at an outside contributor's fork PR head, or at an
unpushed local commit, was auto-approved whenever its .envrc, flake.nix,
and flake.lock matched origin/HEAD. Require HEAD to be contained in some
last-fetched origin branch before running `direnv allow`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated merged commit 0b31264 into main Nov 3, 2026
@kixelated
kixelated deleted the dev-shell-origin-guard branch November 3, 2026 22:14
kixelated added a commit to moq-dev/quest that referenced this pull request Nov 3, 2026
The maintainer judged the auto-allow risk narrow and picked one check:
HEAD must be on an origin branch, shipped in kixelated/dotfiles#35. Record
the decision in the epic, delete the allow-rule quest it settles, and drop
kixtop from repo-config's wait since it has no direnv or Nix.

Co-Authored-By: Claude Opus 5.5 <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.

1 participant