Skip to content

Make worktree push more robust#1135

Merged
Kitenite merged 3 commits intomainfrom
kitenite/push-fail-from-button
Feb 2, 2026
Merged

Make worktree push more robust#1135
Kitenite merged 3 commits intomainfrom
kitenite/push-fail-from-button

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 2, 2026

Summary

  • retry push with explicit HEAD:refs/heads/ when upstream is missing/mismatched
  • tolerate fetch failures for missing remote branch refs during post-push refresh
  • expand upstream-missing detection to include "cannot be resolved to branch"

Testing

  • not run (not requested)

Summary by CodeRabbit

  • Bug Fixes

    • Improved resilience when git operations encounter missing upstream branches during push, fetch, and sync, including worktrees and detached HEAD states.
    • Expanded detection of upstream-related errors to cover additional deletion cases and enable automatic recovery.
  • New Features

    • Terminal attach/open now supports supplying an initial command payload when creating or attaching sessions.
  • Tests

    • Added test coverage for the new upstream-deleted error message pattern.
  • Chores

    • Removed several non-functional runtime comment and tracking handlers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

Added upstream-aware push/retry helpers and expanded upstream-missing error detection; updated fetch/push/sync/createPR flows to retry with --set-upstream when appropriate. Also added one upstream-deleted test string and small non-functional comment/payload adjustments in renderer/hooks.

Changes

Cohort / File(s) Summary
Upstream error detection & tests
apps/desktop/src/lib/trpc/routers/changes/git-utils.ts, apps/desktop/src/lib/trpc/routers/changes/git-operations.test.ts
Extended isUpstreamMissingError to include "cannot be resolved to branch" and added that string to the upstream-deleted test set.
Git operations: push/fetch/sync
apps/desktop/src/lib/trpc/routers/changes/git-operations.ts
Added pushWithSetUpstream and shouldRetryPushWithUpstream; wrapped fetch/push/pull flows with upstream-missing detection, retry logic, and fallback fetch handling.
Renderer startup cleanup
apps/desktop/src/renderer/index.tsx
Removed pageview tracking unsubscribe, deep-link IPC listener/handler, and HMR cleanup logic.
Workspace hooks: payload & comment cleanup
apps/desktop/src/renderer/react-query/workspaces/useOpenWorktree.ts, apps/desktop/src/renderer/react-query/workspaces/useCreateFromPr.ts, apps/desktop/src/renderer/react-query/workspaces/useDeleteWorkspace.ts
Removed non-functional comments; extended createOrAttach mutation payload to include workspaceId and initialCommands.
Minor comment/formatting edits
apps/desktop/src/renderer/routes/.../useHybridSearch.ts, apps/web/src/app/auth/desktop/success/page.tsx, apps/web/src/app/oauth/consent/page.tsx
Removed/simplified inline comments and minor formatting tweaks (e.g., simplified Date construction). No logic changes.

Sequence Diagram

sequenceDiagram
    participant App as Desktop App
    participant GitOps as Git Operations
    participant Remote as Origin/Remote
    participant Handler as Error Handler

    App->>GitOps: request push/createPR/sync/fetch
    activate GitOps
    GitOps->>Remote: attempt git push/fetch/pull
    alt Remote indicates upstream-missing
        GitOps->>Handler: detect upstream-missing (shouldRetryPushWithUpstream)
        Handler-->>GitOps: true
        GitOps->>GitOps: validate HEAD & prepare pushWithSetUpstream
        GitOps->>Remote: git push --set-upstream HEAD:refs/heads/<branch>
        Remote-->>GitOps: success
    else Other error
        Remote-->>GitOps: error
        GitOps-->>App: propagate error
    end
    deactivate GitOps
    GitOps-->>App: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • create commit in change tab #409: Extends upstream-missing detection and adds push-with-upstream retry logic in the same git-operations/git-utils codepaths and tests.

Poem

🐰
I nudge the upstream, sniffing lost refs bright,
I set HEAD forward, retry through the night.
With a hop and a push, the branches align,
Tests now sing clear—our commits feel fine! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description includes a clear summary section but lacks most required template sections including related issues, type of change, and testing details beyond stating tests were not run. Complete the PR description by filling out the missing template sections: explicitly mark the type of change (appears to be Bug fix/Refactor), clarify testing approach, and add any related issue links if applicable.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Make worktree push more robust' directly reflects the main changes: improved push handling for worktrees by retrying with explicit refspec and expanding upstream error detection.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/push-fail-from-button

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@apps/desktop/src/lib/trpc/routers/changes/git-operations.ts`:
- Around line 25-34: The inner catch after the fallback git.fetch(["origin"])
currently swallows all errors; update it to capture the thrown error, derive its
message (error instanceof Error ? error.message : String(error)), and then if
isUpstreamMissingError(message) keep suppressing, otherwise log the failure with
a prefixed context (e.g. "[git/fetch] failed fallback fetch for branch <branch>:
<error>") and either rethrow or surface the error; locate the code around
git.fetch calls and isUpstreamMissingError to implement this behavior and use
the project's logger (or console) consistently.
- Around line 49-52: Replace the thrown plain Error when detecting a detached
HEAD (the trimmedBranch check) with a TRPCError having code BAD_REQUEST;
specifically, import TRPCError from "@trpc/server" (or existing trpc import),
and change the thrown exception in the trimmedBranch/trimmedBranch === "HEAD"
block to: throw new TRPCError({ code: "BAD_REQUEST", message: "Cannot push from
detached HEAD. Please checkout a branch and try again." }); so the router
(git-operations.ts) returns a structured tRPC error instead of a raw Error.

Comment thread apps/desktop/src/lib/trpc/routers/changes/git-operations.ts
Comment thread apps/desktop/src/lib/trpc/routers/changes/git-operations.ts Outdated
- Use TRPCError with BAD_REQUEST for detached HEAD push errors
- Only suppress upstream missing errors in fallback fetch, rethrow others with logging
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

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

Thank you for your contribution! 🎉

@Kitenite Kitenite merged commit 2d8d463 into main Feb 2, 2026
13 checks passed
@Kitenite Kitenite deleted the kitenite/push-fail-from-button branch February 4, 2026 20:42
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.

1 participant