File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 147
147
"icon" : " $(refresh)" ,
148
148
"enablement" : " electron-build-tools:canRefreshPatches"
149
149
},
150
+ {
151
+ "command" : " electron-build-tools.patches.remove" ,
152
+ "title" : " Remove Patch" ,
153
+ "category" : " Electron Build Tools"
154
+ },
150
155
{
151
156
"command" : " electron-build-tools.patches.search" ,
152
157
"title" : " Search Patches" ,
705
710
"command" : " electron-build-tools.patches.refresh" ,
706
711
"when" : " false"
707
712
},
713
+ {
714
+ "command" : " electron-build-tools.patches.remove" ,
715
+ "when" : " false"
716
+ },
708
717
{
709
718
"command" : " electron-build-tools.patches.search" ,
710
719
"when" : " electron-build-tools:active"
826
835
"when" : " view == electron-build-tools:patches && viewItem == repo" ,
827
836
"group" : " inline"
828
837
},
838
+ {
839
+ "command" : " electron-build-tools.patches.remove" ,
840
+ "when" : " view == electron-build-tools:patches && viewItem == patch" ,
841
+ "group" : " 7_modification"
842
+ },
829
843
{
830
844
"command" : " electron-build-tools.removeConfig" ,
831
845
"when" : " view == electron-build-tools:configs && viewItem =~ /^active-config$|^config$/"
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
25
25
hasContentForBlobId ,
26
26
parsePatchConfig ,
27
27
querystringParse ,
28
+ removePatch ,
28
29
setContentForBlobId ,
29
30
startProgress ,
30
31
truncateToLength ,
@@ -111,6 +112,15 @@ export function registerPatchesCommands(
111
112
}
112
113
} ,
113
114
) ,
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
+ ) ,
114
124
vscode . commands . registerCommand (
115
125
`${ commandPrefix } .removePullRequestPatch` ,
116
126
( treeItem : PullRequestTreeItem ) => {
Original file line number Diff line number Diff line change @@ -147,6 +147,29 @@ export async function getPatches(directory: vscode.Uri): Promise<vscode.Uri[]> {
147
147
) ;
148
148
}
149
149
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
+
150
173
export async function getFilesInPatch (
151
174
baseDirectory : vscode . Uri ,
152
175
patch : vscode . Uri ,
You can’t perform that action at this time.
0 commit comments