feat(git): track request source branch as upstream on checkout#730
Merged
Conversation
CheckoutPR fetched a pull/merge request into a synthetic MR<N>/PR<N> branch with no upstream, so the local branch did not reference the remote branch it came from. After checkout, resolve the origin branch whose tip matches the request head (the head ref carries the commit but not the branch name) and set it as upstream. Forks, shallow clones, and ambiguous matches leave the branch untracked, preserving prior behavior.
✅ Deploy Preview for images-devsy-sh canceled.
|
✅ Deploy Preview for devsydev canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesCheckoutPR source tracking
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
skevetter
marked this pull request as ready for review
July 24, 2026 04:04
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.
Summary
CheckoutPRfetches a pull/merge request into a syntheticMR<N>/PR<N>local branch with no upstream, so the local branch does not reference the remote branch the request was opened from (git statusshows no tracking relationship).After checkout, this resolves the origin branch whose tip matches the request head and sets it as the local branch's upstream. Because the head ref (
refs/{pull,merge-requests}/N/head) carries the tip commit but not the source branch name, the match is done by commit viagit for-each-ref --points-atover the already-fetchedrefs/remotes/origin/*— no provider API, token, or network call required.It degrades cleanly to the prior behavior (untracked branch) when the match can't be trusted:
originWorks identically for GitHub and GitLab (including self-hosted).
Adds
TestRepoCheckoutPRTracksSourceBranchandTestRepoCheckoutPRAmbiguousSourceBranchLeftUntracked.Summary by CodeRabbit