Fix checkout of local pull request branches without PR metadata #7069
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.
This PR fixes an issue where users couldn't check out local pull request branches that weren't originally created through the extension's PR checkout flow.
Problem
The
PullRequestGitHelper.checkoutExistingPullRequestBranch()
method only looked for branches with PR metadata in git configs. If a user had a local branch with the same name as a PR's head ref but without the associated metadata (e.g., created manually or through other tools), the method would returnfalse
instead of attempting to check out the matching local branch.Solution
Enhanced the method with a fallback mechanism that:
pullRequest.head.ref
false
if no matching local branch existsExample
Before this fix:
After this fix:
Testing
Added comprehensive tests covering:
The implementation follows existing code patterns, includes appropriate error handling and logging, and makes minimal surgical changes to the codebase.
Fixes #6994.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.