Skip to content

Fix checkout of local pull request branches without PR metadata #7069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 24, 2025

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 return false instead of attempting to check out the matching local branch.

Solution

Enhanced the method with a fallback mechanism that:

  1. Preserves existing behavior: Still prioritizes branches with PR metadata in git configs
  2. Adds fallback logic: When no branches with PR metadata are found, attempts to checkout a local branch matching pullRequest.head.ref
  3. Auto-associates metadata: When the fallback succeeds, automatically associates the branch with PR metadata for future use
  4. Graceful failure: Returns false if no matching local branch exists

Example

Before this fix:

// User has local branch "feature-branch" but no PR metadata
const result = await checkoutExistingPullRequestBranch(repository, pullRequest, progress);
// Returns false, branch not checked out

After this fix:

// User has local branch "feature-branch" matching PR head ref
const result = await checkoutExistingPullRequestBranch(repository, pullRequest, progress);
// Returns true, branch checked out and associated with PR

Testing

Added comprehensive tests covering:

  • ✅ Checkout local branch without PR metadata
  • ✅ Return false for nonexistent branches
  • ✅ Prioritize branches with existing PR metadata
  • ✅ Maintain backward compatibility

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.

Copilot AI and others added 2 commits June 24, 2025 10:03
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Can't check out a local pull request branch Fix checkout of local pull request branches without PR metadata Jun 24, 2025
@Copilot Copilot AI requested a review from alexr00 June 24, 2025 10:05
Copilot finished work on behalf of alexr00 June 24, 2025 10:05
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot delete the comments

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 24, 2025

@copilot delete the comments

Done. Removed the comments from the fallback logic while preserving all functionality. e58b5ec

@Copilot Copilot AI requested a review from alexr00 June 24, 2025 10:26
Copilot finished work on behalf of alexr00 June 24, 2025 10:26
@alexr00 alexr00 closed this Jun 27, 2025
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.

Can't check out a local pull request branch
2 participants