Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

Implementation Complete: Delete Branch After Merge Setting

  • Add new configuration setting githubPullRequests.deleteBranchAfterMerge in package.json
  • Add localized string for the setting description in package.nls.json
  • Add setting key constant in src/common/settingKeys.ts
  • Modify merge logic in src/github/pullRequestOverview.ts to check setting and auto-delete branch
  • Modify merge logic in src/github/activityBarViewProvider.ts to check setting and auto-delete branch
  • Create autoDeleteBranchesAfterMerge function to silently delete branches without prompts
  • Address code review feedback (extract helper, improve error handling, remove unrelated file)
  • Refactor to reuse more of deleteBranch logic via shared performBranchDeletion helper
  • Run security checks (CodeQL - no issues found)
  • All linting and hygiene checks passed

Summary

This PR implements a new setting githubPullRequests.deleteBranchAfterMerge that automatically deletes branches after a pull request is successfully merged.

Key Features

  • New Setting: githubPullRequests.deleteBranchAfterMerge (boolean, default: false)
  • Silent Operation: Uses existing deletion preferences without showing prompts
  • Respects User Preferences: Uses defaultDeletionMethod.selectLocalBranch and selectRemote settings
  • Error Handling: Graceful error handling with logging - failures don't block merge
  • Code Reuse: Extracted performBranchDeletion() helper shared by both interactive and automatic deletion

Technical Implementation

  1. Added setting in package.json with localized description
  2. Created performBranchDeletion() helper containing core deletion logic
  3. autoDeleteBranchesAfterMerge() builds action list and calls shared helper
  4. Interactive deleteBranch() now also uses shared helper (with user prompts for dirty trees)
  5. Integrated auto-delete call in merge handlers (pullRequestOverview.ts and activityBarViewProvider.ts)

Security & Quality

  • ✅ CodeQL security scan: No issues found
  • ✅ ESLint: All checks passed
  • ✅ Code hygiene: All checks passed
  • ✅ Code review feedback addressed

Ready for final review and merge!

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature Request: Settings Option - Delete Branch after Merge</issue_title>
<issue_description>

Proposed Reasoning

My workplace has the policy of "delete branch after Peer Review and Merge", I can imagine others may have the same.
What I'm proposing is a settings option for Delete Branches after Merge

<label>Delete Branches after Merge</label>
<select>
    <option>Always Ask</option>
    <option>Do Not Automatically Delete(default)</option> 
    <option>Automatically Delete Local After Merge</option> 
    <option>Automatically Delete Local and Remote After Merge</option>
</select>

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 8, 2025 12:19
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Add settings option for deleting branches after merge Add setting to automatically delete branches after merge Dec 8, 2025
Copilot AI requested a review from alexr00 December 8, 2025 12:38
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.

We should be able to re-use more of deleteBranch in pullRequestReviewCommon.ts isntead of fully having a new function.

… helper

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

Copilot AI commented Dec 11, 2025

We should be able to re-use more of deleteBranch in pullRequestReviewCommon.ts isntead of fully having a new function.

Refactored to extract a shared performBranchDeletion() helper function that contains the core deletion logic. Both the interactive deleteBranch() and automatic autoDeleteBranchesAfterMerge() now use this shared helper, eliminating code duplication. The interactive version retains special handling for dirty working trees with user prompts. (4cb17f1)

Copilot AI requested a review from alexr00 December 11, 2025 11:21
@alexr00 alexr00 marked this pull request as ready for review December 11, 2025 11:50
@alexr00 alexr00 enabled auto-merge (squash) December 11, 2025 11:50
@vs-code-engineering vs-code-engineering bot added this to the December / January 2026 milestone Dec 11, 2025
@alexr00 alexr00 merged commit e30b8f8 into main Dec 11, 2025
6 checks passed
@alexr00 alexr00 deleted the copilot/add-delete-branch-option branch December 11, 2025 13:50
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.

Feature Request: Settings Option - Delete Branch after Merge

3 participants