@@ -253,42 +253,43 @@ export class SvnCommands {
253253 }
254254
255255 @command ( "svn.add" )
256- async addFile ( resource : Resource ) {
257- const repository = this . model . getRepository ( resource . resourceUri . fsPath ) ;
256+ async addFile (
257+ ...resourceStates : SourceControlResourceState [ ]
258+ ) : Promise < void > {
259+ const selection = this . getResourceStates ( resourceStates ) ;
258260
259- if ( ! repository ) {
261+ if ( selection . length === 0 ) {
260262 return ;
261263 }
262264
263- try {
264- await repository . addFile ( resource . resourceUri . fsPath ) ;
265- } catch ( error ) {
266- console . log ( error ) ;
267- window . showErrorMessage ( "Unable to add file" ) ;
268- }
265+ const uris = selection . map ( resource => resource . resourceUri ) ;
266+
267+ await this . runByRepository ( uris , async ( repository , resources ) => {
268+ if ( ! repository ) {
269+ return ;
270+ }
271+
272+ const paths = resources . map ( resource => resource . fsPath ) ;
273+
274+ try {
275+ await repository . addFile ( paths ) ;
276+ } catch ( error ) {
277+ console . log ( error ) ;
278+ window . showErrorMessage ( "Unable to add file" ) ;
279+ }
280+ } ) ;
269281 }
270282
271283 @command ( "svn.addChangelist" )
272284 async addChangelist (
273285 ...resourceStates : SourceControlResourceState [ ]
274286 ) : Promise < void > {
275- if (
276- resourceStates . length === 0 ||
277- ! ( resourceStates [ 0 ] . resourceUri instanceof Uri )
278- ) {
279- const resource = this . getSCMResource ( ) ;
287+ const selection = this . getResourceStates ( resourceStates ) ;
280288
281- if ( ! resource ) {
282- return ;
283- }
284-
285- resourceStates = [ resource ] ;
289+ if ( selection . length === 0 ) {
290+ return ;
286291 }
287292
288- const selection = resourceStates . filter (
289- s => s instanceof Resource
290- ) as Resource [ ] ;
291-
292293 const uris = selection . map ( resource => resource . resourceUri ) ;
293294
294295 await this . runByRepository ( uris , async ( repository , resources ) => {
@@ -345,23 +346,12 @@ export class SvnCommands {
345346 async removeChangelist (
346347 ...resourceStates : SourceControlResourceState [ ]
347348 ) : Promise < void > {
348- if (
349- resourceStates . length === 0 ||
350- ! ( resourceStates [ 0 ] . resourceUri instanceof Uri )
351- ) {
352- const resource = this . getSCMResource ( ) ;
353-
354- if ( ! resource ) {
355- return ;
356- }
349+ const selection = this . getResourceStates ( resourceStates ) ;
357350
358- resourceStates = [ resource ] ;
351+ if ( selection . length === 0 ) {
352+ return ;
359353 }
360354
361- const selection = resourceStates . filter (
362- s => s instanceof Resource
363- ) as Resource [ ] ;
364-
365355 const uris = selection . map ( resource => resource . resourceUri ) ;
366356
367357 await this . runByRepository ( uris , async ( repository , resources ) => {
@@ -742,8 +732,10 @@ export class SvnCommands {
742732 }
743733
744734 @command ( "svn.revert" )
745- async revert ( ...resourceStates : Resource [ ] ) {
746- if ( resourceStates . length === 0 ) {
735+ async revert ( ...resourceStates : SourceControlResourceState [ ] ) : Promise < void > {
736+ const selection = this . getResourceStates ( resourceStates ) ;
737+
738+ if ( selection . length === 0 ) {
747739 return ;
748740 }
749741
@@ -757,18 +749,22 @@ export class SvnCommands {
757749 return ;
758750 }
759751
760- try {
761- const paths = resourceStates . map ( state => {
762- return state . resourceUri ;
763- } ) ;
752+ const uris = selection . map ( resource => resource . resourceUri ) ;
764753
765- await this . runByRepository ( paths , async ( repository , paths ) =>
766- repository . revert ( paths )
767- ) ;
768- } catch ( error ) {
769- console . error ( error ) ;
770- window . showErrorMessage ( "Unable to revert" ) ;
771- }
754+ await this . runByRepository ( uris , async ( repository , resources ) => {
755+ if ( ! repository ) {
756+ return ;
757+ }
758+
759+ const paths = resources . map ( resource => resource . fsPath ) ;
760+
761+ try {
762+ await repository . revert ( paths ) ;
763+ } catch ( error ) {
764+ console . log ( error ) ;
765+ window . showErrorMessage ( "Unable to revert" ) ;
766+ }
767+ } ) ;
772768 }
773769
774770 @command ( "svn.update" , { repository : true } )
@@ -799,12 +795,15 @@ export class SvnCommands {
799795 }
800796 }
801797
802- @command ( "svn.remove" , { repository : true } )
803- async remove (
804- repository : Repository ,
805- ...resourceStates : Resource [ ]
806- ) : Promise < void > {
807- let keepLocal ;
798+ @command ( "svn.remove" )
799+ async remove ( ...resourceStates : SourceControlResourceState [ ] ) : Promise < void > {
800+ const selection = this . getResourceStates ( resourceStates ) ;
801+
802+ if ( selection . length === 0 ) {
803+ return ;
804+ }
805+
806+ let keepLocal : boolean ;
808807 const answer = await window . showWarningMessage (
809808 "Would you like to keep a local copy of the files?." ,
810809 "Yes" ,
@@ -821,16 +820,22 @@ export class SvnCommands {
821820 keepLocal = false ;
822821 }
823822
824- try {
825- const paths = resourceStates . map ( state => {
826- return state . resourceUri . fsPath ;
827- } ) ;
823+ const uris = selection . map ( resource => resource . resourceUri ) ;
828824
829- const result = await repository . removeFiles ( paths , keepLocal ) ;
830- } catch ( error ) {
831- console . error ( error ) ;
832- window . showErrorMessage ( "Unable to remove files" ) ;
833- }
825+ await this . runByRepository ( uris , async ( repository , resources ) => {
826+ if ( ! repository ) {
827+ return ;
828+ }
829+
830+ const paths = resources . map ( resource => resource . fsPath ) ;
831+
832+ try {
833+ const result = await repository . removeFiles ( paths , keepLocal ) ;
834+ } catch ( error ) {
835+ console . log ( error ) ;
836+ window . showErrorMessage ( "Unable to remove files" ) ;
837+ }
838+ } ) ;
834839 }
835840
836841 @command ( "svn.resolve" , { repository : true } )
@@ -868,7 +873,12 @@ export class SvnCommands {
868873 @command ( "svn.log" , { repository : true } )
869874 async log ( repository : Repository ) {
870875 try {
871- const result = await repository . log ( ) ;
876+ const logPromise = repository . log ( ) ;
877+ window . withProgress (
878+ { location : ProgressLocation . Window , title : "Fetching logs" } ,
879+ ( ) => logPromise
880+ ) ;
881+ const result = await logPromise ;
872882 // send the log results to a new tab
873883 workspace . openTextDocument ( { content : result } ) . then ( doc => {
874884 window . showTextDocument ( doc ) ;
@@ -904,6 +914,25 @@ export class SvnCommands {
904914 }
905915 }
906916
917+ private getResourceStates (
918+ resourceStates : SourceControlResourceState [ ]
919+ ) : Resource [ ] {
920+ if (
921+ resourceStates . length === 0 ||
922+ ! ( resourceStates [ 0 ] . resourceUri instanceof Uri )
923+ ) {
924+ const resource = this . getSCMResource ( ) ;
925+
926+ if ( ! resource ) {
927+ return [ ] ;
928+ }
929+
930+ resourceStates = [ resource ] ;
931+ }
932+
933+ return resourceStates . filter ( s => s instanceof Resource ) as Resource [ ] ;
934+ }
935+
907936 private runByRepository < T > (
908937 resource : Uri ,
909938 fn : ( repository : Repository , resource : Uri ) => Promise < T >
0 commit comments