Skip to content

Fix PR creation from origin-based worktrees - #3218

Merged
juliusmarminge merged 2 commits into
mainfrom
t3code/fix-origin-worktree-pr
Jun 20, 2026
Merged

Fix PR creation from origin-based worktrees#3218
juliusmarminge merged 2 commits into
mainfrom
t3code/fix-origin-worktree-pr

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Jun 20, 2026

Copy link
Copy Markdown
Member

Summary

  • compare origin-based worktrees against the remote base before a stale local branch
  • preserve the selected base ref as worktree branch metadata for PR creation
  • cover remote-ahead/local-behind worktrees with regression tests

Validation

  • vp test packages/contracts/src/git.test.ts apps/server/src/vcs/GitVcsDriverCore.test.ts apps/server/src/server.test.ts
  • vp check
  • vp run typecheck

Note

Medium Risk
Touches PR generation, worktree bootstrap, and base-branch resolution in git workflows; behavior changes are targeted but affect stacked git actions and thread worktree creation.

Overview
Fixes PR creation and generated PR content when a feature branch was cut from a fetched remote default branch while the local default ref is still behind origin.

GitManager adds resolveBaseRangeRef so auto-generated PR titles/bodies diff against the remote-tracking commit for the resolved base branch (e.g. origin/main’s SHA), not a stale local main. A regression test covers remote-ahead / local-behind worktrees with gh-merge-base set.

Worktree bootstrap threads optional baseRefName through VcsCreateWorktreeInput, ws.ts, and createWorktree, which persists branch.<newRefName>.gh-merge-base so later PR flows know the intended base.

GitVcsDriverCore prefers an existing remote-tracking branch over a same-named local branch when resolving base candidates, and tests assert correct merge-base config and zero ahead counts for origin-fetched worktrees.

Reviewed by Cursor Bugbot for commit e030293. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix PR creation from origin-based worktrees by using remote tracking commit as range base

  • Adds a resolveBaseRangeRef helper in GitManager.ts that resolves the base branch to the remote tracking commit SHA when a primary remote exists, falling back to the local branch name.
  • Updates runStackedAction to use this resolved ref when calling readRangeContext, so PR content excludes commits already on the remote base.
  • Stores branch.<newRefName>.gh-merge-base in git config when creating a worktree with a baseRefName, enabling correct ancestry tracking for origin-based worktrees.
  • Changes resolveUpstreamRefNameFromCandidates to prefer remote-prefixed refs over local branches when both exist.
  • Behavioral Change: bootstrap worktree creation now passes baseRefName, which triggers the new git config write; upstream ref resolution now prefers remote over local when both are present.

Macroscope summarized e030293.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 564affca-2440-43d6-9f75-d09a81e7b5d2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/fix-origin-worktree-pr

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jun 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: PR range uses local base
    • In runPrStep, the base branch for readRangeContext is now resolved to the remote tracking ref (e.g. origin/main) using resolvePrimaryRemoteName, with a fallback to the local ref if the remote-qualified ref is unavailable, aligning PR range computation with the status/divergence path.

Create PR

Or push these changes by commenting:

@cursor push f3d8594d49

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 1d107bd. Configure here.

Comment thread apps/server/src/vcs/GitVcsDriverCore.ts
@macroscopeapp

macroscopeapp Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Straightforward bug fix that ensures PR content is generated against the remote base branch rather than a potentially stale local base. Changes are well-scoped with comprehensive test coverage and backwards-compatible schema additions.

You can customize Macroscope's approvability policy. Learn more.

@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Jun 20, 2026
@juliusmarminge
juliusmarminge merged commit 335e0b5 into main Jun 20, 2026
16 checks passed
@juliusmarminge
juliusmarminge deleted the t3code/fix-origin-worktree-pr branch June 20, 2026 06:38
aaditagrawal added a commit to aaditagrawal/t3code that referenced this pull request Jun 24, 2026
…ettings-imports

Fix PR creation from origin-based worktrees (pingdotgg#3218)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant