Allow adding projects without a worktree (bare and empty repos)
Allow adding projects without a usable worktree: bare repos become first-class addable projects (never fake workspaces), and empty repos get an in-app recovery path to their first workspace.
ELI5
Imagine Orca is being handed a project folder. Before this change, if that folder was Git storage without a normal checkout, or a brand-new repo with no first commit yet, Orca could get stuck or show confusing options. This PR teaches Orca to tell those cases apart: bare repos can be used as sources for new workspaces, and empty repos get a safe in-app button to make the first commit and keep going.
What changed
Bare repos (addable storage, never openable workspaces):
- Bare entries are hidden from workspace rows and excluded from default-checkout selection.
- Bare entries no longer flow into the hidden "imported worktrees" card, which previously offered a "Show in worktree list" button that silently did nothing for them.
- Bare repos with commits work as full worktree sources (Create Workspace resolves the default base and
git worktree addruns against the bare cwd).
Empty (unborn) repos:
- The "No base branch found" workspace-creation error now offers a Create initial commit button. It creates an empty initial commit via plumbing (
commit-treeon the empty tree + create-only CASupdate-ref) — never touching the index or working tree, so staged files are never swept into the recovery commit — then resumes workspace creation in place with the new ref as the explicit base. - Guard ladder makes the action idempotent and safe: no-ops when a default base resolves, when HEAD already has commits (detached HEAD returns the sha), or when any local/remote branch exists (resumes from it instead of minting an empty
main); staleorigin/HEADsymrefs are verified before being trusted; supports sha1 and sha256 object formats and custom default-branch names. - Wired with full parity: local IPC, relay-SSH via a dedicated
git.createInitialCommitRPC (the generic relaygit.execsurface stays read-only), runtime RPC (with theconnectionIddouble-hop branch), web preload shim, and the mobile RPC allowlist. Per-repo in-flight serialization coalesces concurrent calls. - Composer recovery replays the original submit kind (quick vs full) with the explicit base, guarded against double-submit, repo switches (before and during the action, on both success and failure paths), and modal dismissal mid-action.
- Add Project shows a one-shot informational toast when the added repo has no commits (two-step check so repos with commits on unprobed branches are not mislabeled).
Design approach
Investigated the original report ("unable to add a project without a worktree (or an empty commit)") and separated the two conflated states: unborn repos (working tree, no commits) and bare repos (commits possible, no working tree). The contract: Add Project answers "is this valid git storage", workspace cards answer "is there a working tree", Create Workspace answers "is there a real base ref" — and every dead end gets an in-app exit. The existing base-ref safety invariant (never guess origin/main) is preserved; the recovery button is the exit. A scoped implementation design doc was written and review-hardened before implementation (kept local; docs/** is gitignored).
Pipeline evidence
- Design review: 2 rounds (parallel Claude + Codex reviewers). Round 1 surfaced two P1 design gaps (relay-SSH routing; custom-default-branch retry loop that would stack empty commits) — both designed out before implementation. Round 2 P2/P3 findings (concurrency serialization, runtime
connectionIdparity, detached-HEAD fallback, validation-plan gaps) applied. - Implementation: initial Claude pass completed by Codex after a session interruption.
- Completeness verification: independent read-only pass — every requirement MET; four test-coverage gaps closed in a follow-up (which also caught and fixed a real bug: bare HEAD targets are validated to
refs/heads/*beforeupdate-ref). - Code-review loop: 5 rounds, two independent reviewers per round (Claude + Codex), all validated findings fixed:
- R1: relay validator allowlist blocked the SSH path entirely (P1, masked by a mock that never reached the commit step); web-preload shim missing → typecheck break (P1); quick-create resubmit used the wrong submit path (P2); staged-files-swept-into-commit risk (P2); sha256 break (P2/P3); weak/vacuous test assertions (P3s).
- R2: validator write carve-outs too broad → replaced with the dedicated relay RPC and
git.execreverted to read-only (P1); empty-mainminted when commits exist on unprobed branches → existing-branch resume guard (P2); mobile allowlist gap (P2); double-submit window (P3). - R3: stale recovery button surviving repo switch (High/P3); modal-dismissal mid-action resubmit (P3).
- R4: failure-path repo-switch guard gap (P3).
- R5: both reviewers CLEAN.
- Rejected (documented accepted risk): transient ref-listing failure could show the informational unborn toast spuriously.
- brennan-test-changes: LAND. All five product-surface scenarios verified live in a dedicated dev Electron instance: unborn add + toast; "No base branch found" → Create initial commit → workspace created without reopening the dialog (plumbing commit on
main, index/working tree untouched); bare-with-commits add (zero workspace rows, no dead-end affordance) + end-to-end workspace creation from the bare source; bare unborn recovery (refs/heads/maincreated, submit resumed); normal-repo regression (no toast, unchanged flow). Lint exit 0;git diff --checkclean; focused suites 311 tests + full relay suite 414 tests green. One load-sensitive real-git test flake observed once under concurrent lint, 5/5 green after. - Static checks / tests: full touched-suite vitest runs green throughout (~410 tests across the touched suites at last full pass);
pnpm typecheckclean (node, tc.cli, tc.web).
SSH live e2e (added after initial review)
Live validation over a real SSH relay (throwaway Linux Docker target, relay built from this branch, real UI driving) per the SSH test rig:
- Unborn repo over SSH: quick-create fails with the recovery panel, clicking Create initial commit lands an empty-tree commit on the remote (
HEADtree4b825dc..., index/working tree clean), and creation resumes to a working remote worktree. VERIFIED. - Bare unborn repo over SSH: addable as a project (0 workspaces), recovery creates
refs/heads/<branch>via plumbing on the remote, creation resumes. VERIFIED. - The generic relay
git.execsurface remains read-only (validator suites: 162 tests).
Two real gaps were found by this testing and fixed in-branch:
- Quick-create recovery regression: after merging main, quick-create routes through background creation, whose failure panel (Retry/Dismiss) never surfaced the recovery action. The pending-creation entry now carries the error action, the panel renders Create initial commit, and a successful commit patches the request's
baseBranchwith the returned ref before retrying. - Bare repos could not be added over SSH: the relay-side
git.isGitRepoonly ranrev-parse --show-toplevel; it now falls back to--is-bare-repository, matching local validation.
Assumptions / accepted gaps
- The unborn-repo hint can theoretically toast spuriously if ref enumeration fails transiently right after a successful add — accepted (one-shot informational toast; the add itself just exercised git).
- After a failed recovery (e.g. missing git identity), the replacement error has no action button; pressing Create again re-surfaces it — judged acceptable by review.
- sha256 and custom-default-branch variants proven by real-git unit tests, not in-app. An old deployed relay lacking the new RPC degrades gracefully to an error in the recovery surface.
- Bonus-only observation from SSH testing: default-base inference for a bare repo with commits did not infer in one throwaway SSH setup (explicit base worked; local default-base inference for bare repos is verified). Recorded as a possible follow-up, not blocking.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
This pull request implements a complete "create initial commit" feature for unborn Git repositories, enabling users to seed empty repos with a first commit when workspace creation fails due to missing base refs. The change spans from low-level Git plumbing (commit-tree, update-ref with compare-and-swap) through relay RPC handlers, main-process runtime routing, preload IPC bridge, and renderer-side composition of a recovery action UI. Bare repositories are handled consistently throughout, hidden from default checkout and worktree visibility. An "unborn repository hint" toast is displayed when newly added Git repos have no commits.
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 7.55% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
| Description check | ⚠️ Warning | The description is detailed, but it does not follow the required template and lacks explicit Screenshots, AI Review Report, and Security Audit sections. | Add the missing template sections and align the current content under Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The PR title accurately and concisely summarizes the main change: enabling projects to be added without a traditional worktree (bare and empty repositories). |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✨ Finishing Touches
📝 Generate docstrings
- [ ] Create stacked PR
- [ ] Commit on current branch
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 @coderabbitai help to get the list of available commands.
Ready to review this PR? Stage has broken it down into 8 individual chapters for you:
Chapters generated by Stage for commit e5bb6c6bb6f83188409302f6db2f8572ece84e8e on Jul 1, 2026 11:22pm UTC.
Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-02T20:05:02Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.