@@ -106,7 +106,7 @@ export class SvnCommands {
106
106
107
107
if ( repository ) {
108
108
repositoryPromise = Promise . resolve ( repository ) ;
109
- } else if ( this . model . openRepositories . length === 1 ) {
109
+ } else if ( this . model . repositories . length === 1 ) {
110
110
repositoryPromise = Promise . resolve ( this . model . repositories [ 0 ] ) ;
111
111
} else {
112
112
repositoryPromise = this . model . pickRepository ( ) ;
@@ -117,7 +117,7 @@ export class SvnCommands {
117
117
return Promise . resolve ( ) ;
118
118
}
119
119
120
- return Promise . resolve ( method . apply ( this , [ repository , args ] ) ) ;
120
+ return Promise . resolve ( method . apply ( this , [ repository , ... args ] ) ) ;
121
121
} ) ;
122
122
}
123
123
@@ -184,9 +184,12 @@ export class SvnCommands {
184
184
}
185
185
186
186
@command ( "svn.commit" , { repository : true } )
187
- async commit ( repository : Repository , ...args : any [ ] [ ] ) : Promise < void > {
187
+ async commit (
188
+ repository : Repository ,
189
+ ...resourceStates : Resource [ ]
190
+ ) : Promise < void > {
188
191
try {
189
- const paths = args [ 0 ] . map ( state => {
192
+ const paths = resourceStates . map ( state => {
190
193
return state . resourceUri . fsPath ;
191
194
} ) ;
192
195
const message = await inputCommitMessage ( ) ;
@@ -205,8 +208,9 @@ export class SvnCommands {
205
208
}
206
209
207
210
@command ( "svn.refresh" , { repository : true } )
208
- refresh ( repository : Repository ) {
211
+ async refresh ( repository : Repository ) {
209
212
repository . update ( ) ;
213
+ repository . updateBranches ( ) ;
210
214
}
211
215
212
216
async openDiff ( resource : Resource , against : string ) {
@@ -302,8 +306,12 @@ export class SvnCommands {
302
306
await repository . branch ( name ) ;
303
307
}
304
308
305
- @command ( "svn.revert" , { repository : true } )
306
- async revert ( repository : Repository , ...args : any [ ] [ ] ) {
309
+ @command ( "svn.revert" )
310
+ async revert ( ...resourceStates : Resource [ ] ) {
311
+ if ( resourceStates . length === 0 ) {
312
+ return ;
313
+ }
314
+
307
315
const yes = "Yes I'm sure" ;
308
316
const answer = await window . showWarningMessage (
309
317
"Are you sure? This will wipe all local changes." ,
@@ -315,12 +323,13 @@ export class SvnCommands {
315
323
}
316
324
317
325
try {
318
- const paths = args [ 0 ] . map ( state => {
319
- return state . resourceUri . fsPath ;
326
+ const paths = resourceStates . map ( state => {
327
+ return state . resourceUri ;
320
328
} ) ;
321
329
322
- await repository . repository . revert ( paths ) ;
323
- repository . update ( ) ;
330
+ await this . runByRepository ( paths , async ( repository , paths ) =>
331
+ repository . repository . revert ( paths )
332
+ ) ;
324
333
} catch ( error ) {
325
334
console . error ( error ) ;
326
335
window . showErrorMessage ( "Unable to revert" ) ;
@@ -337,4 +346,48 @@ export class SvnCommands {
337
346
window . showErrorMessage ( "Unable to update" ) ;
338
347
}
339
348
}
349
+
350
+ private runByRepository < T > (
351
+ resource : Uri ,
352
+ fn : ( repository : Repository , resource : Uri ) => Promise < T >
353
+ ) : Promise < T [ ] > ;
354
+ private runByRepository < T > (
355
+ resources : Uri [ ] ,
356
+ fn : ( repository : Repository , resources : Uri [ ] ) => Promise < T >
357
+ ) : Promise < T [ ] > ;
358
+ private async runByRepository < T > (
359
+ arg : Uri | Uri [ ] ,
360
+ fn : ( repository : Repository , resources : any ) => Promise < T >
361
+ ) : Promise < T [ ] > {
362
+ const resources = arg instanceof Uri ? [ arg ] : arg ;
363
+ const isSingleResource = arg instanceof Uri ;
364
+
365
+ const groups = resources . reduce (
366
+ ( result , resource ) => {
367
+ const repository = this . model . getRepository ( resource ) ;
368
+
369
+ if ( ! repository ) {
370
+ console . warn ( "Could not find git repository for " , resource ) ;
371
+ return result ;
372
+ }
373
+
374
+ const tuple = result . filter ( p => p . repository === repository ) [ 0 ] ;
375
+
376
+ if ( tuple ) {
377
+ tuple . resources . push ( resource ) ;
378
+ } else {
379
+ result . push ( { repository, resources : [ resource ] } ) ;
380
+ }
381
+
382
+ return result ;
383
+ } ,
384
+ [ ] as { repository : Repository ; resources : Uri [ ] } [ ]
385
+ ) ;
386
+
387
+ const promises = groups . map ( ( { repository, resources } ) =>
388
+ fn ( repository as Repository , isSingleResource ? resources [ 0 ] : resources )
389
+ ) ;
390
+
391
+ return Promise . all ( promises ) ;
392
+ }
340
393
}
0 commit comments