Skip to content

fix(cli): hooks allow in a directory outside any git repository - #109

Merged
justinjdev merged 1 commit into
mainfrom
fix/hooks-outside-git-repo
Sep 6, 2026
Merged

justinjdev merged 1 commit into
mainfrom
fix/hooks-outside-git-repo

Conversation

@justinjdev

@justinjdev justinjdev commented Sep 6, 2026 •

Copy link
Copy Markdown
Owner

Found by the first local smoke test of #108: a Claude Code session started in a plain directory (not inside any git repository) had every Bash, Edit and Write call blocked by gate-guard with:

fellowship: cannot read fellowship state (db: resolve main repo: git rev-parse --git-common-dir: exit status 128) — blocking for safety.

That included pwd and the cleanup command, so the session could not even git init the repo it was meant to test against. The bug predates #108: StorePath surfaced git's "not a git repository" as a generic store error, and gate hooks read any such error as "the store exists but cannot be read" and failed closed.

Fix

  • gitutil.RunGitContext tells git's "not a git repository" answer apart from every other failure (gitutil.ErrNotARepository).
  • db.StorePath maps it to ErrNoStore: outside a repo there is no main repo to key a store to, so there is no store — the same answer as a repo without one. storeOpenExit then takes its existing no-store path: hooks allow, fellowship commands report "no fellowship state in this repo".
  • Every other git failure (git missing, a timeout, a corrupt repo) still fails closed for gate hooks, as before.

TestStoreOpen_OutsideAnyRepoAllowsHooks covers all six hooks and the status command from a plain temp directory. go test -race ./..., vet and gofmt are clean. Changelog updated in README and the site.

🤖 Generated with Claude Code


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Hooks now allow Bash, Edit, and Write operations in directories outside Git repositories.
    • Fellowship commands now report that no fellowship state exists instead of displaying a Git repository error.
  • Documentation

    • Updated the unreleased changelog to document the improved behavior outside Git repositories.

A session started in a plain directory had every Bash, Edit and Write
blocked by gate-guard: resolving the main repo failed with git's "not a
git repository", which surfaced as a generic store error and gate hooks
read that as "the store cannot be read" and failed closed. Outside a repo
there is no main repo to key a store to, so there is no store — the same
answer as a repo without one — and hooks allow. gitutil now tells that
git answer apart (ErrNotARepository) and StorePath maps it to ErrNoStore.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XpCG85waNcdZjvMQE82QfT
@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 53c94b04-4aa7-4b30-9019-586d9d683f8e

📥 Commits

Reviewing files that changed from the base of the PR and between c6211b4 and 67a2a88.

📒 Files selected for processing (5)
  • README.md
  • cli/cmd/fellowship/hook_test.go
  • cli/internal/db/db.go
  • cli/internal/gitutil/gitutil.go
  • site/src/routes/changelog/+page.svelte

📝 Walkthrough

Walkthrough

The change classifies Git’s non-repository error as ErrNoStore. Store lookup then treats directories outside Git repositories like repositories without fellowship state. Tests verify hook and status results, and changelogs document the behavior.

Changes

Non-repository store handling

Layer / File(s) Summary
Git error classification and store resolution
cli/internal/gitutil/gitutil.go, cli/internal/db/db.go
RunGitContext returns ErrNotARepository for Git’s non-repository error. StorePath maps that error to ErrNoStore.
Hook behavior and changelog validation
cli/cmd/fellowship/hook_test.go, README.md, site/src/routes/changelog/+page.svelte
Tests verify that hooks allow outside repositories, status exits with code 1, and no store directory is created. Changelogs document the behavior.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hooks-outside-git-repo

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.

@justinjdev
justinjdev enabled auto-merge September 6, 2026 19:47
@justinjdev
justinjdev disabled auto-merge September 6, 2026 19:47
@justinjdev
justinjdev merged commit a8bd70c into main Sep 6, 2026
4 of 5 checks passed
@justinjdev
justinjdev deleted the fix/hooks-outside-git-repo branch September 6, 2026 19:47
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.

2 participants