Repository navigation
fix(host-service): bypass user git hooks for scaffolding initial commits - #6320
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRepository scaffolding now bypasses rejecting global Git hooks for in-place initialization, empty repositories, and template clones. Tests confirm that ordinary commits remain subject to the hooks. ChangesScaffold commit hook handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant UI as Client UI
participant API as TRPC Router
participant Workspace as workspaces.createSession
participant RepoUtils as resolve-repo.ts
participant Git as SimpleGit (local)
participant Hooks as User Global Git Hooks
participant FS as Filesystem
Note over UI,FS: Session Creation / Repo Scaffolding Flow
UI->>API: createSession
API->>Workspace: initialize workspace
Workspace->>RepoUtils: initEmptyRepo(sessionsRoot, name)
alt initEmptyRepo path
RepoUtils->>Git: gitInitMainBranch(targetPath)
Git->>FS: git init --initial-branch=main
FS-->>Git: repo initialized
RepoUtils->>Git: raw(["-c", "core.hooksPath=", "commit", "--no-verify", "--allow-empty", "-m", "Initial commit"])
Note over Git: Bypasses user hooks via empty hooksPath + --no-verify
Git->>FS: commit (hooks bypassed)
FS-->>Git: commit success
Git-->>RepoUtils: ok
else initLocalRepoInPlace path
RepoUtils->>Git: gitInitMainBranch(repoPath)
Git->>FS: git init --initial-branch=main
FS-->>Git: repo initialized
RepoUtils->>Git: raw(["-c", "core.hooksPath=", "commit", "--no-verify", "--allow-empty", "-m", "Initial commit"])
Note over Git: Same hook bypass applied
Git->>FS: commit (hooks bypassed)
FS-->>Git: commit success
Git-->>RepoUtils: ok
else cloneTemplateInto path
RepoUtils->>Git: clone template into targetPath
Git-->>RepoUtils: repo cloned
RepoUtils->>Git: add(".")
Git->>FS: stage files
FS-->>Git: staged
RepoUtils->>Git: raw([...scaffoldCommitArgs, "-m", "Initial commit"])
Note over Git: Bypass covers template snapshot commit too
Git->>FS: commit (hooks bypassed)
FS-->>Git: commit success
Git-->>RepoUtils: ok
end
alt hook bypass succeeds
RepoUtils-->>Workspace: resolved repo path
Workspace-->>API: session created
API-->>UI: success response
else git identity or disk error
RepoUtils->>RepoUtils: asInitialCommitTrpcError(err)
RepoUtils-->>Workspace: TRPCError
Workspace-->>API: error
API-->>UI: error response (500/400)
end
Note over Git,Hooks: User global hooks are never triggered for scaffolding commits
Note over Git: createUserSimpleGit already allowsUnsafeHooksPath, enabling the override
Problem
Creating a session (
workspaces.createSession→initEmptyRepo) initializes a fresh repo under the sessions root and makes a scaffolding "Initial commit". If the user has global git hooks configured (e.g. acore.hooksPathcommit-msg hook enforcing a commit-message policy), the hook runs against our scaffolding commit and rejects it — session creation deterministically fails as INTERNAL_SERVER_ERROR for any user with such a hook (2 events on 1.20.0).Root cause
The scaffolding "Initial commit" invocations in
resolve-repo.ts(initEmptyRepo,initLocalRepoInPlace,cloneTemplateInto) run plaingit commit, so the user's machine-wide hooks apply to commits we author in repos we just created.asInitialCommitTrpcErrortypes git-user-not-configured but a hook rejection falls through to a 500.Fix
Run all three scaffolding commits with hooks bypassed:
-c core.hooksPath= commit --no-verify. Both parts are needed —--no-verifyskips pre-commit/commit-msg, and the emptycore.hooksPathoverride covers hooks--no-verifydoesn't (verified empirically: a failingprepare-commit-msgstill aborts a--no-verifycommit).createUserSimpleGitalready enablesallowUnsafeHooksPath, so simple-git permits the override.Decision on the
cloneTemplateIntosnapshot path (commits the user's template files into a repo we just initialized): bypass there too. The user does not author that commit invocation either, and a rejecting global hook fails template creation identically — same failure mode, same fix.asInitialCommitTrpcErrorclassification is kept unchanged for what can still fail (git identity not configured, disk errors). No hook-rejection classification was added since the bypass covers every scaffolding path — there is no remaining path where a hook can reject these commits.Precedent: #6168 (hook tolerance in workspace setup).
Also fixed a latent test-fixture hazard found along the way: simple-git only fails a raw task on non-zero exit when stderr is non-empty, so the regression tests' rejecting hooks print to stderr like real policy hooks do (a silent
exit 1hook is swallowed by simple-git — noted in the test comment).Verification
bunx biome checkon both changed files:cd packages/host-service && bun run typecheck:bun test packages/host-service/src/trpc/router/project/utils/resolve-repo.test.ts:Mutation check — with the bypass reverted to plain
git commit, the three new regression tests fail; restored, all 34 pass:Refs HOST-SERVICE-13
https://claude.ai/code/session_1a228bdc-29c4-4d4e-8e63-7bb4acf54aaf
Summary by cubic
Bypass user git hooks for scaffolding “Initial commit” during session repo setup to prevent 500s when global hooks reject commits. Aligns with HOST-SERVICE-13 by ensuring session creation doesn’t depend on user git hook policies.
-c core.hooksPath=and--no-verifyininitEmptyRepo,initLocalRepoInPlace, andcloneTemplateInto.simple-gitsurfaces failures via stderr.Written for commit 355a72f. Summary will update on new commits.
Summary by CodeRabbit