fix(branch): avoid fork PR fetch collision with checked-out branch#1466
Open
syf2211 wants to merge 1 commit into
Open
fix(branch): avoid fork PR fetch collision with checked-out branch#1466syf2211 wants to merge 1 commit into
syf2211 wants to merge 1 commit into
Conversation
For cross-repository PRs, fetch the pull head into a namespaced remote ref instead of refs/heads/<headRefName>. When the fork head branch name matches the runner's currently checked-out branch, check out the PR head in detached mode to avoid repointing the local branch. Otherwise create/update a local branch from the fetched PR head so git push keeps working for differently named fork heads. Fixes anthropics#1423
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
Fixes fork PR checkout failures in tag-mode workflows when the fork head branch name matches the branch already checked out on the runner (e.g.
main).Motivation
setupBranchfetched cross-repo PR heads withpull/<N>/head:<headRefName>, which writes intorefs/heads/<headRefName>. If that branch is currently checked out, git refuses with:This breaks
issue_comment/ tag-mode runs on fork PRs opened from the fork's default branch.Fixes #1423
Changes
refs/remotes/pull/<N>/head+) so reruns can update the ref safelygit pushkeeps working for differently named fork headsTests
bun test test/fork-pr-branch-checkout.test.ts— passbun run typecheck— passNotes
Detached checkout is only used for the collision case described in #1423. Non-colliding fork PRs still get a local branch at
headRefName.