Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9a79d4c

Browse files
committedMay 12, 2025··
feat(patches): add remove command to context menu
1 parent 8453dba commit 9a79d4c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
 

‎package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@
147147
"icon": "$(refresh)",
148148
"enablement": "electron-build-tools:canRefreshPatches"
149149
},
150+
{
151+
"command": "electron-build-tools.patches.remove",
152+
"title": "Remove Patch",
153+
"category": "Electron Build Tools"
154+
},
150155
{
151156
"command": "electron-build-tools.patches.search",
152157
"title": "Search Patches",
@@ -705,6 +710,10 @@
705710
"command": "electron-build-tools.patches.refresh",
706711
"when": "false"
707712
},
713+
{
714+
"command": "electron-build-tools.patches.remove",
715+
"when": "false"
716+
},
708717
{
709718
"command": "electron-build-tools.patches.search",
710719
"when": "electron-build-tools:active"
@@ -826,6 +835,11 @@
826835
"when": "view == electron-build-tools:patches && viewItem == repo",
827836
"group": "inline"
828837
},
838+
{
839+
"command": "electron-build-tools.patches.remove",
840+
"when": "view == electron-build-tools:patches && viewItem == patch",
841+
"group": "7_modification"
842+
},
829843
{
830844
"command": "electron-build-tools.removeConfig",
831845
"when": "view == electron-build-tools:configs && viewItem =~ /^active-config$|^config$/"

‎src/commands/patches.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
hasContentForBlobId,
2626
parsePatchConfig,
2727
querystringParse,
28+
removePatch,
2829
setContentForBlobId,
2930
startProgress,
3031
truncateToLength,
@@ -111,6 +112,15 @@ export function registerPatchesCommands(
111112
}
112113
},
113114
),
115+
vscode.commands.registerCommand(
116+
`${commandPrefix}.patches.remove`,
117+
async (patchTreeItem: Patch) => {
118+
await vscode.workspace.fs.delete(patchTreeItem.resourceUri);
119+
await removePatch(patchTreeItem.resourceUri);
120+
121+
patchesProvider.refresh();
122+
},
123+
),
114124
vscode.commands.registerCommand(
115125
`${commandPrefix}.removePullRequestPatch`,
116126
(treeItem: PullRequestTreeItem) => {

‎src/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ export async function getPatches(directory: vscode.Uri): Promise<vscode.Uri[]> {
147147
);
148148
}
149149

150+
export async function removePatch(patch: vscode.Uri): Promise<void> {
151+
const directory = vscode.Uri.joinPath(patch, "..");
152+
const patchListFile = vscode.Uri.joinPath(directory, ".patches");
153+
const patchListFileContent = (
154+
await vscode.workspace.fs.readFile(patchListFile)
155+
)
156+
.toString()
157+
.trim();
158+
159+
const patches = patchListFileContent.split("\n");
160+
const patchIndex = patches.findIndex(
161+
(filename) => filename === path.basename(patch.fsPath),
162+
);
163+
164+
if (patchIndex !== -1) {
165+
patches.splice(patchIndex, 1);
166+
await vscode.workspace.fs.writeFile(
167+
patchListFile,
168+
Buffer.from(patches.join("\n") + "\n", "utf8"),
169+
);
170+
}
171+
}
172+
150173
export async function getFilesInPatch(
151174
baseDirectory: vscode.Uri,
152175
patch: vscode.Uri,

0 commit comments

Comments
 (0)
Please sign in to comment.