fix(git-merge): fetch upstream before merging a local branch#280
Merged
Conversation
git-merge's docstring promised "fetch + merge" but never fetched, so `git-merge master` merged the stale local ref. When origin moved ahead, the merge silently missed the new commits — a fix that had landed on origin/master "wasn't there" and a failing job kept failing. _fresh_merge_ref() now resolves the ref's upstream, fetches it, and if the local branch is behind, merges the upstream (latest) instead with a loud note. Offline / no-upstream / fetch-fail cases warn and fall back to the local ref. Remote-tracking refs are refreshed directly. Two real-repo tests (bare remote + stale clone) cover the redirect and the local-only fallback. Co-Authored-By: Max <noreply>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
git-merge's docstring promised "fetch (optional) + merge" but the code never fetched. Sogit-merge mastermerged the localmasterref — stale the moment origin moves ahead.Real bite this session: a timeout fix had landed on
origin/master, but mergingmasterinto a feature branch silently used the lagging local ref. The fix "wasn't there" and the failing CI job kept failing — with no signal that the merge was a no-op against an old base.Fix
New
_fresh_merge_ref():git fetches it before merging.origin/master) with a loud note:local master was N behind origin/master — merging origin/master (latest) instead.origin/master) are refreshed directly.Tests
Two real-repo tests (bare remote + stale clone, no mocking):
test_merge_redirects_to_upstream_when_local_stale— advances origin via a second clone, asserts the merge pulls the upstream commit.test_merge_local_only_branch_no_fetch— a branch with no upstream merges as-is.Full git/merge suite: 376 passed, 1 skipped.
🤖 Generated by Max — the stale-merge fix, fittingly, almost shipped stale.