Skip to content

fix(desktop): use --no-track instead of ^{commit} in v1 createWorktree#3548

Merged
Kitenite merged 1 commit intomainfrom
fix/3448-workspace-setup
Apr 18, 2026
Merged

fix(desktop): use --no-track instead of ^{commit} in v1 createWorktree#3548
Kitenite merged 1 commit intomainfrom
fix/3448-workspace-setup

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Apr 18, 2026

Summary

  • v1 createWorktree appended ^{commit} to the start point to suppress upstream tracking. Git rejects this with fatal: invalid reference when the ref isn't locally resolvable with that suffix (stale/missing remote-tracking ref, slash-containing branch names like feat/workstreams-view).
  • Replace with the --no-track flag — same intent, no ref parsing pitfall. Matches v2's host-service flow, which has always used --no-track.
  • Adds two regression tests covering origin/main as start point and a slash-containing branch (the exact Workspace setup failed #3448 repro).

Closes #3448

Test plan

  • bun test apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts — 33 pass, including the two new cases
  • bun run typecheck in apps/desktop — clean
  • bun run lint on the changed files — clean

Summary by cubic

Switch v1 createWorktree to use --no-track instead of appending ^{commit} to the start point to disable upstream tracking. This prevents invalid ref errors from remote refs and slash-named branches and matches v2 behavior; fixes #3448.

  • Bug Fixes
    • Use --no-track with git worktree add -b <branch>, passing worktreePath and startPoint directly (no ^{commit}).
    • Avoids "fatal: invalid reference" with origin/main and branches like feat/workstreams-view.
    • Added regression tests for both cases.

Written for commit 4e248e1. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved worktree creation behavior to prevent automatic upstream branch tracking when using remote branches as starting points.
  • Tests

    • Added test coverage for worktree creation with various branch naming patterns and tracking configurations.

v1's createWorktree appended ^{commit} to the start point to prevent
implicit upstream tracking. This fails with "fatal: invalid reference"
when the ref isn't locally resolvable with that suffix (e.g. stale or
missing remote-tracking ref, branches with slashes like
feat/workstreams-view).

Replace ^{commit} with --no-track, which has the same effect without
fragile ref suffix manipulation. Matches v2's host-service approach.

Closes #3448
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0be8588a-58a3-4d7f-8207-d160782b9304

📥 Commits

Reviewing files that changed from the base of the PR and between 867ef87 and 4e248e1.

📒 Files selected for processing (2)
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts

📝 Walkthrough

Walkthrough

Updated git worktree add invocation to use --no-track with positional arguments instead of ^{commit} syntax, resolving failures when creating worktrees from local branches containing slashes. Added comprehensive test coverage for remote tracking refs and slash-containing branch names.

Changes

Cohort / File(s) Summary
Git Worktree Core Logic
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts
Changed git worktree add command from using ${startPoint}^{commit} to --no-track with positional arguments <worktreePath> <startPoint>, fixing invalid reference errors on local branches with slashes in names.
Git Worktree Tests
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts
Added two new tests: one verifying --no-track prevents upstream tracking when using remote refs (origin/main), another confirming worktree creation succeeds with local branches containing slashes (feat/workstreams-view).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A worktree fix, so clean and bright,
With slashes in branches—now we get it right!
No more ^{commit} causing despair,
Just --no-track and positional care! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing ^{commit} with --no-track in createWorktree, which directly addresses the reported issue.
Description check ✅ Passed The description is comprehensive, covering the problem statement, solution approach, related issue closure, and test results against the provided template.
Linked Issues check ✅ Passed The PR successfully addresses issue #3448 by replacing the fragile ^{commit} suffix with --no-track, preventing invalid reference errors for slash-containing branch names and remote refs.
Out of Scope Changes check ✅ Passed All changes are tightly scoped to fixing the createWorktree issue: implementation change in git.ts and two regression tests in git.test.ts, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/3448-workspace-setup

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 and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 18, 2026

Greptile Summary

This PR fixes a fatal: invalid reference error in the v1 createWorktree function that occurred when the start point was either a stale/missing remote-tracking ref or a slash-containing branch name (e.g. feat/workstreams-view, reproducing issue #3448). The old approach appended ^{commit} to the start point argument passed to git worktree add to suppress upstream tracking — but git's object-syntax parsing of <ref>^{commit} is unreliable in those edge cases. The fix replaces that hack with the --no-track flag, which achieves the same goal (no automatic upstream tracking) without any ref-parsing pitfalls, and aligns with how v2's host-service flow has always behaved.

  • Root cause fixed (git.ts): createWorktree now passes --no-track instead of appending ^{commit} to the start-point argument in the git worktree add call.
  • Two regression tests added (git.test.ts): one covering origin/main as start point (verifying no tracking is set up), and one reproducing the exact feat/workstreams-view slash-branch scenario from Workspace setup failed #3448.
  • No changes to createWorktreeFromExistingBranch, createWorktreeFromPr, or any other worktree paths.
  • The existing push.autoSetupRemote = true config step is preserved, ensuring the first git push still wires up upstream tracking automatically.

Confidence Score: 5/5

Safe to merge — targeted, well-tested fix with no broader regressions expected.

The change is minimal and correct: replacing an unreliable ref-syntax hack (^{commit}) with the purpose-built --no-track flag. It aligns with the v2 code path that has always used --no-track, is covered by two new regression tests that exercise the exact failure scenarios from the bug report, and doesn't touch any other code paths. push.autoSetupRemote continuity is preserved. No security or data-loss surface introduced.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.ts Replaced startPoint^{commit} with --no-track flag in createWorktree; fix is targeted, correct, and consistent with the v2 flow. No other functions changed.
apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts Two new regression tests added to the createWorktree hook tolerance suite — one for origin/main as start point and one for slash-containing branch names; both properly validate the --no-track behavior.

Sequence Diagram

sequenceDiagram
    participant C as Caller
    participant CW as createWorktree()
    participant EWA as execWorktreeAdd()
    participant Git as git worktree add

    C->>CW: branch, worktreePath, startPoint

    Note over CW: OLD (broken)
    CW->>EWA: args=[..., "-b", branch, worktreePath, "startPoint^{commit}"]
    EWA->>Git: git worktree add -b branch path startPoint^{commit}
    Git-->>EWA: fatal: invalid reference (stale ref / slash branch)

    Note over CW: NEW (this PR)
    CW->>EWA: args=["--no-track", "-b", branch, worktreePath, startPoint]
    EWA->>Git: git worktree add --no-track -b branch path startPoint
    Git-->>EWA: worktree created, no upstream tracking set

    EWA-->>CW: success
    CW->>Git: git config --local push.autoSetupRemote true
    Note over Git: First git push will auto-set upstream
    CW-->>C: resolved
Loading

Reviews (1): Last reviewed commit: "fix(desktop): use --no-track instead of ..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts">

<violation number="1" location="apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts:445">
P2: These regression tests don’t reproduce the old `^{commit}` failure, so they won’t catch a reintroduction of the bug.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@@ -441,6 +441,89 @@ describe("createWorktree hook tolerance", () => {
createWorktree(repoPath, "feature/existing-path", worktreePath, "HEAD"),
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: These regression tests don’t reproduce the old ^{commit} failure, so they won’t catch a reintroduction of the bug.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/lib/trpc/routers/workspaces/utils/git.test.ts, line 445:

<comment>These regression tests don’t reproduce the old `^{commit}` failure, so they won’t catch a reintroduction of the bug.</comment>

<file context>
@@ -441,6 +441,89 @@ describe("createWorktree hook tolerance", () => {
 		).rejects.toThrow("already exists");
 	}, 10_000);
+
+	test("works with remote-tracking ref as start point (no-track prevents upstream)", async () => {
+		// Set up a "remote" repo with a commit, then clone it so we have origin/<branch> refs
+		const originPath = join(TEST_DIR, "worktree-notrack-origin");
</file context>
Fix with Cubic

@Kitenite Kitenite merged commit bb657ec into main Apr 18, 2026
7 checks passed
@Kitenite Kitenite deleted the fix/3448-workspace-setup branch April 18, 2026 06:23
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

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.

Workspace setup failed

1 participant