fix: fall back to local mode for empty repos with no commits#2150
fix: fall back to local mode for empty repos with no commits#2150alecramos-sudo wants to merge 3 commits into
Conversation
Empty git repositories (git init, no commits) report isRepo=true but branch=null. In worktree mode this caused an instant crash: git worktree add fails without commits, the bootstrap cleanup deletes the thread, and the user gets stranded on a dead route with "select a thread." resolveSendEnvMode now checks branch availability and falls back to local mode when worktree mode is requested but no branch exists. Fixes pingdotgg#2148
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d99c628. Configure here.
ApprovabilityVerdict: Approved A small, well-tested bug fix that gracefully handles empty git repositories (initialized but no commits) by falling back to local mode instead of failing. The change is backward compatible with clear documentation and comprehensive test coverage. You can customize Macroscope's approvability policy. Learn more. |
Drop `?? null` from the branch call site so `undefined` (git status query still loading) is not conflated with `null` (empty repo, no commits). This prevents worktree users from being incorrectly downgraded to local mode while the query resolves. Update the type signature to explicitly accept `undefined` to satisfy exactOptionalPropertyTypes.

What Changed
resolveSendEnvMode()now checks branch availability alongsideisGitRepo. When the user's default env mode is"worktree"but the repo has no branch (i.e. an empty repo with zero commits), it falls back to"local"mode instead of proceeding into a guaranteed crash.Three files changed, 28 lines added, 3 removed:
ChatView.logic.ts— added optionalbranchparam toresolveSendEnvMode; returns"local"when worktree is requested butbranch === nullChatView.tsx— passesgitStatusQuery.data?.branchat the call siteChatView.logic.test.ts— 3 new test cases (empty repo fallback, local-on-empty, backward compat when branch not provided)Why
Empty git repositories (
git init, no commits) reportisRepo: truebutbranch: null— the status line reads# branch.head (initial), parsed asnullinGitCore.ts. In worktree mode this triggers a crash:resolveSendEnvModeseesisGitRepo=true→ keeps"worktree"modegit worktree add→ fails (no commits to branch from)thread.delete→ draft is clearedThe fix is the smallest correct change: detect the missing branch client-side and fall back to local mode before the bootstrap ever runs. No server changes needed.
Fixes #2148
Checklist
Note
Low Risk
Small client-side guard in chat send env resolution with tests; no server or auth changes.
Overview
Fixes empty git repos defaulting to worktree and crashing during bootstrap when
git worktree addhas no commits to branch from.resolveSendEnvModenow accepts optionalbranchfrom git status:branch === null(empty repo) forceslocalwhen worktree was requested;undefined(status still loading) leaves the requested mode unchanged.ChatViewpassesgitStatusQuery.data?.branchinto that helper. Unit tests cover empty-repo fallback, explicit local, and callers that omitbranch.Reviewed by Cursor Bugbot for commit 36672fc. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fall back to local mode in
resolveSendEnvModefor empty git repos with no commitsWhen a git repo has no commits,
branchisnulland worktree mode is not meaningful.resolveSendEnvModein ChatView.logic.ts now returns"local"in this case. Whenbranchisundefined(still loading), the requested mode is preserved unchanged. ChatView.tsx passesgitStatusQuery.data?.branchtoresolveSendEnvModeto enable this behavior.Macroscope summarized 36672fc.