Skip to content

feat: update from origin/main without altering local branches#113

Closed
guplem wants to merge 1 commit into
pol-rivero:mainfrom
guplem:fix/update-from-origin-main
Closed

feat: update from origin/main without altering local branches#113
guplem wants to merge 1 commit into
pol-rivero:mainfrom
guplem:fix/update-from-origin-main

Conversation

@guplem

@guplem guplem commented Mar 29, 2026

Copy link
Copy Markdown

Summary

Follow-up to #111 as suggested by @pol-rivero.

After PR #111 added a fetch before the merge, performFetch also fast-forwards local branches as a side effect.
By merging origin/main directly (instead of local main) and skipping the fast-forward step, we avoid unintended changes to local branches.

So, instead of merging the local default branch (e.g. main), with this PR it merges the remote tracking branch (e.g. origin/main) directly. This means the "Update from Default Branch" action no longer alters local branches as a side effect. The menu label now reflects this (e.g. "Update from origin/main").

Changes

app/src/ui/app.tsx

  • Made updateBranchWithContributionTargetBranch() async so it can await the fetch before merging.
  • After fetching, resolves the remote tracking branch (e.g. origin/main) from allBranches and merges that instead of the local branch. Falls back to the local branch if no remote tracking branch is found.
  • Added getRemoteTrackingBranch() helper: for remote branches (fork case) returns the branch as-is; for local branches, looks up the corresponding remote branch via the upstream field.

app/src/ui/dispatcher/dispatcher.ts

  • Added fetchWithoutFastForward(): exposes the new app-store method to the UI layer.

app/src/lib/stores/app-store.ts

  • Added skipFastForward parameter to performFetch(). When true, skips the fastForwardBranches() call so local branches are not altered.
  • Added _fetchWithoutFastForward() public method that calls performFetch with skipFastForward: true.
  • Updated the menu label source to use the branch's upstream name (e.g. origin/main) instead of the local name (e.g. main), so the menu reads "Update from origin/main".

Test plan

  • Click Branch > Update from origin/main when the remote default branch has unpulled commits. Confirm the fetch runs and the merge succeeds.
  • Click Branch > Update from origin/main when the branch is genuinely up to date. Confirm the app correctly reports "already up to date".
  • Verify the local main branch is NOT fast-forwarded after the operation.
  • Verify the menu label shows "Update from origin/main" (or the appropriate remote branch name).
  • For fork repos contributing to parent: verify the menu shows "Update from upstream/main" and merges the upstream remote branch.

Instead of merging the local default branch (e.g. `main`), merge the
remote tracking branch (e.g. `origin/main`) after fetching. This avoids
altering local branches as a side effect of the update operation.

- Fetch without fast-forwarding local branches before merging
- Find and merge the remote tracking branch instead of the local one
- Update the menu label to show the remote ref (e.g. "Update from origin/main")

Follow-up to PR desktop#111 as suggested by @pol-rivero.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@guplem guplem force-pushed the fix/update-from-origin-main branch from 4ca527b to 9067ba3 Compare March 29, 2026 19:17
@pol-rivero

Copy link
Copy Markdown
Owner

This looks promising. I'll have a closer look later today

@pol-rivero

Copy link
Copy Markdown
Owner

I did some tests and this doesn't seem to be working...

This is what I did:

  1. Go to main and make sure it's behind origin/main
image
  1. Switch to a different branch (which is up-to-date with main but not origin/main)
  2. Select "Branch" -> "Update from origin/main"
  3. I would expect it to merge in the changes from origin/main, but instead it claims it's already up-to-date:
image

In any case, you don't need to fix this problem, because I've been thinking about your original fix (fast-forwarding the main branch) and I now think that it was probably better than my proposal of merging the remote branch directly. I can't think of any case where fast-forwarding the main branch could be undesirable, and the diff of that PR is much smaller/cleaner than this one.
Sorry for making you waste time on this PR 😕

@guplem

guplem commented Mar 30, 2026

Copy link
Copy Markdown
Author

Uoops, I might have done something wrong, obviously… but yeah, I agree with you that this is probably not necessary. I was just trying to make everyone happy :)

So yeah, I am closing this PR then.

@guplem guplem closed this Mar 30, 2026
@pol-rivero

Copy link
Copy Markdown
Owner

Thanks for understanding ❤️

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.

2 participants