Conversation
Co-authored-by: alexr00 <[email protected]>
Co-authored-by: alexr00 <[email protected]>
Co-authored-by: alexr00 <[email protected]>
Copilot
AI
changed the title
[WIP] Wrong commit is checked out when local branch exists with the same name
Fix wrong commit checkout when local branch exists with same name as PR
Sep 24, 2025
alexr00
requested changes
Sep 25, 2025
src/github/pullRequestGitHelper.ts
Outdated
Comment on lines
107
to
109
| // Delete and recreate the local branch to point to the remote commit | ||
| await repository.deleteBranch(branchName, true); | ||
| await repository.createBranch(branchName, false, trackedBranch.commit); |
Member
There was a problem hiding this comment.
@copilot This is dangerous. We shouldn't just delete the user's local branch. Instead, we should create a local branch with a different, available, name, and point the branch's remote to the correct upstream branch.
Contributor
Author
There was a problem hiding this comment.
You're absolutely right - that was dangerous. I've fixed it to create a unique branch name (using the existing calculateUniqueBranchNameForPR function) instead of deleting the user's branch. The fix in commit d440a0d now:
- Preserves the user's local branch with their work intact
- Creates a new branch with a unique name (e.g.,
pr/author/123) - Points the new branch to the correct remote commit
- Sets up proper upstream tracking
- Checks out the new unique branch
This approach protects the user's work while still ensuring they get the correct PR code.
- Addressed feedback from @alexr00 about dangerous branch deletion - Instead of deleting user's local branch, create unique branch name - Use existing calculateUniqueBranchNameForPR function for naming - Preserve user's work by never touching their original branch - New approach follows existing PR branch naming patterns
Co-authored-by: alexr00 <[email protected]>
Copilot stopped work on behalf of
alexr00 due to an error
September 25, 2025 10:55
alexr00
approved these changes
Sep 25, 2025
rebornix
approved these changes
Sep 25, 2025
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.
✅ UPDATED: Safe approach to avoid deleting user's local branch
Addressed feedback from @alexr00: The original approach of deleting the user's local branch was dangerous and could lose user work.
🔧 New Safe Approach
Instead of deleting the user's local branch when it has a different commit than the PR:
calculateUniqueBranchNameForPRfunction (e.g.,pr/author/123)✅ Changes Made
src/github/pullRequestGitHelper.tsdeleteBranchoperationcalculateUniqueBranchNameForPRfunctionsrc/test/github/pullRequestGitHelper.test.ts🎯 User Experience
pr/author/numberpatternThis approach is much safer and follows the existing patterns in the codebase for handling PR branches.
Fixes #7702
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.