Skip to content

Commit 9800419

Browse files
authored
Fix delete branch after merge for merge queues (#8437)
Fixes #8435
1 parent af46c2e commit 9800419

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"githubPullRequests.fileAutoReveal.description": "Automatically reveal open files in the pull request changes tree.",
4242
"githubPullRequests.defaultDeletionMethod.selectLocalBranch.description": "When true, the option to delete the local branch will be selected by default when deleting a branch from a pull request.",
4343
"githubPullRequests.defaultDeletionMethod.selectRemote.description": "When true, the option to delete the remote will be selected by default when deleting a branch from a pull request.",
44-
"githubPullRequests.deleteBranchAfterMerge.description": "Automatically delete the branch after merging a pull request. This setting only applies when the pull request is merged through this extension.",
44+
"githubPullRequests.deleteBranchAfterMerge.description": "Automatically delete the branch after merging a pull request. This setting only applies when the pull request is merged through this extension. When using merge queues, this will only delete the local branch.",
4545
"githubPullRequests.terminalLinksHandler.description": "Default handler for terminal links.",
4646
"githubPullRequests.terminalLinksHandler.github": "Create the pull request on GitHub.",
4747
"githubPullRequests.terminalLinksHandler.vscode": "Create the pull request in VS Code.",

src/github/pullRequestOverview.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
874874

875875
private async enqueue(message: IRequestMessage<void>): Promise<void> {
876876
const result = await this._item.enqueuePullRequest();
877+
878+
// Check if auto-delete branch setting is enabled
879+
const deleteBranchAfterMerge = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(DELETE_BRANCH_AFTER_MERGE, false);
880+
if (deleteBranchAfterMerge && result) {
881+
// For merge queues, only delete the local branch since the PR isn't merged yet
882+
await PullRequestReviewCommon.autoDeleteLocalBranchAfterEnqueue(this._folderRepositoryManager, this._item);
883+
}
884+
877885
this._replyMessage(message, { mergeQueueEntry: result });
878886
}
879887

src/github/pullRequestReviewCommon.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,39 @@ export namespace PullRequestReviewCommon {
427427
return deletedBranchTypes;
428428
}
429429

430+
/**
431+
* Automatically delete the local branch after adding to a merge queue.
432+
* Only deletes the local branch since the PR isn't merged yet.
433+
*/
434+
export async function autoDeleteLocalBranchAfterEnqueue(folderRepositoryManager: FolderRepositoryManager, item: PullRequestModel): Promise<void> {
435+
const branchInfo = await folderRepositoryManager.getBranchNameForPullRequest(item);
436+
const defaultBranch = await folderRepositoryManager.getPullRequestRepositoryDefaultBranch(item);
437+
438+
// Get user preference for local branch deletion
439+
const deleteLocalBranch = vscode.workspace
440+
.getConfiguration(PR_SETTINGS_NAMESPACE)
441+
.get<boolean>(`${DEFAULT_DELETION_METHOD}.${SELECT_LOCAL_BRANCH}`, true);
442+
443+
if (!branchInfo || !deleteLocalBranch) {
444+
return;
445+
}
446+
447+
const selectedActions: SelectedAction[] = [{ type: 'local' }];
448+
449+
// Execute deletion
450+
const deletedBranchTypes = await performBranchDeletion(folderRepositoryManager, item, defaultBranch, branchInfo, selectedActions);
451+
452+
// Show notification
453+
if (deletedBranchTypes.includes('local')) {
454+
const branchName = branchInfo.branch || item.head?.ref;
455+
if (branchName) {
456+
vscode.window.showInformationMessage(
457+
vscode.l10n.t('Deleted local branch {0}.', branchName)
458+
);
459+
}
460+
}
461+
}
462+
430463
/**
431464
* Automatically delete branches after merge based on user preferences.
432465
* This function does not show any prompts - it uses the default deletion method preferences.

0 commit comments

Comments
 (0)