Skip to content

fix: enable diverged branch sync and target origin repo for PR creation#1678

Open
42tg wants to merge 1 commit intopingdotgg:mainfrom
42tg:fix/diverged-branch-sync
Open

fix: enable diverged branch sync and target origin repo for PR creation#1678
42tg wants to merge 1 commit intopingdotgg:mainfrom
42tg:fix/diverged-branch-sync

Conversation

@42tg
Copy link
Copy Markdown

@42tg 42tg commented Apr 2, 2026

Summary

  • When a local branch has diverged from its upstream (e.g. after a force-push), allow force-pull (reset to upstream) if the working tree is clean
  • Pass --repo flag to gh pr create so PRs target the correct fork repository instead of defaulting to upstream parent
  • Update GitActionsControl UI with new pull menu item for diverged branches

Test plan

  • Force-push a branch remotely, verify the UI offers a sync option
  • Verify PR creation targets the correct repository in a fork setup
  • Verify diverged sync is blocked when working tree has uncommitted changes

Note

Medium Risk
Medium risk because gitPull can now hard-reset a diverged branch to its upstream, discarding local commits when the working tree is clean. Also changes PR creation targeting via gh --repo, which could affect fork/upstream selection.

Overview
Improves git syncing and PR creation in forked/diverged scenarios.

On the server, gitPull now falls back to a new GitCore.resetToUpstream (hard reset to @{upstream}) when a fast-forward pull fails due to true divergence (ahead+behind) and the working tree is clean; it blocks this fallback when there are local uncommitted changes.

For PR creation, GitManager now resolves the origin repository owner/repo and passes it through GitHubCli.createPullRequest, which forwards it to gh pr create via --repo to ensure PRs are opened against the correct fork. The web UI adds a Pull/Sync (force pull) action (menu + quick action), wires it to the pull mutation with toasts, and updates logic/tests to enable sync on diverged clean branches.

Written by Cursor Bugbot for commit 3b7ec8c. This will update automatically on new commits. Configure here.

Note

Add pull/sync action to git controls and fix PR creation to target origin repo

  • Adds a Pull menu item and quick action to GitActionsControl; labels it 'Sync (force pull)' when the branch has diverged, 'Pull' otherwise
  • When a diverged branch has a clean working tree, the gitPull WS handler now hard-resets to upstream via a new resetToUpstream command instead of failing
  • When the working tree has uncommitted changes on a diverged branch, the pull is blocked with a message to stash or commit first
  • Passes --repo <owner/repo> to gh pr create using the origin remote's repository name, fixing PR creation in forks
  • Risk: resetToUpstream performs a hard reset (git reset --hard), discarding any local commits on the branch without additional confirmation

Macroscope summarized 3b7ec8c.

@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

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: 7beeb8ed-c706-4f48-8f00-94bb3fafbd21

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

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.

@42tg 42tg force-pushed the fix/diverged-branch-sync branch from 97e3ada to 5c61505 Compare April 2, 2026 10:30
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

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 and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@42tg 42tg force-pushed the fix/diverged-branch-sync branch from 5c61505 to 5a3e8ae Compare April 2, 2026 10:40
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 2, 2026

Approvability

Verdict: Needs human review

This PR enables automatic hard reset to upstream when pulling a diverged branch, which can discard local commits. This is a significant runtime behavior change with potential data loss implications that warrants careful human review.

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

@42tg 42tg force-pushed the fix/diverged-branch-sync branch from 5a3e8ae to 660273a Compare April 2, 2026 10:47
- Branch sync: when local branch diverges from remote, allow force-pull
  (reset to upstream) if working tree is clean
- PR creation: pass --repo flag to gh pr create so PRs target the
  correct fork repository
- Update GitActionsControl tests for new pull menu item
@42tg 42tg force-pushed the fix/diverged-branch-sync branch from 660273a to 3b7ec8c Compare April 2, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant