@@ -198,7 +198,7 @@ async function exec(child: cp.ChildProcess, cancellationToken?: CancellationToke
198198 }
199199
200200 if ( cancellationToken && cancellationToken . isCancellationRequested ) {
201- throw new GitError ( { message : 'Cancelled' } ) ;
201+ throw new CancellationError ( ) ;
202202 }
203203
204204 const disposables : IDisposable [ ] = [ ] ;
@@ -239,7 +239,7 @@ async function exec(child: cp.ChildProcess, cancellationToken?: CancellationToke
239239 // noop
240240 }
241241
242- e ( new GitError ( { message : 'Cancelled' } ) ) ;
242+ e ( new CancellationError ( ) ) ;
243243 } ) ;
244244 } ) ;
245245
@@ -568,12 +568,21 @@ export class Git {
568568 }
569569
570570 const startExec = Date . now ( ) ;
571- const bufferResult = await exec ( child , options . cancellationToken ) ;
572- const durExec = Date . now ( ) - startExec ;
571+ let bufferResult : IExecutionResult < Buffer > ;
572+
573+ try {
574+ bufferResult = await exec ( child , options . cancellationToken ) ;
575+ } catch ( ex ) {
576+ if ( ex instanceof CancellationError ) {
577+ this . log ( `> git ${ args . join ( ' ' ) } [${ Date . now ( ) - startExec } ms] (cancelled)\n` ) ;
578+ }
579+
580+ throw ex ;
581+ }
573582
574583 if ( options . log !== false ) {
575584 // command
576- this . log ( `> git ${ args . join ( ' ' ) } [${ durExec } ms]\n` ) ;
585+ this . log ( `> git ${ args . join ( ' ' ) } [${ Date . now ( ) - startExec } ms]\n` ) ;
577586
578587 // stdout
579588 if ( bufferResult . stdout . length > 0 && args . find ( a => this . commandsToLog . includes ( a ) ) ) {
@@ -2119,7 +2128,11 @@ export class Repository {
21192128 . map ( ( [ ref ] ) => ( { name : ref , type : RefType . Head } as Branch ) ) ;
21202129 }
21212130
2122- async getRefs ( opts ?: { sort ?: 'alphabetically' | 'committerdate' ; contains ?: string ; pattern ?: string ; count ?: number } ) : Promise < Ref [ ] > {
2131+ async getRefs ( opts ?: { sort ?: 'alphabetically' | 'committerdate' ; contains ?: string ; pattern ?: string ; count ?: number ; cancellationToken ?: CancellationToken } ) : Promise < Ref [ ] > {
2132+ if ( opts ?. cancellationToken && opts ?. cancellationToken . isCancellationRequested ) {
2133+ throw new CancellationError ( ) ;
2134+ }
2135+
21232136 const args = [ 'for-each-ref' ] ;
21242137
21252138 if ( opts ?. count ) {
@@ -2140,7 +2153,7 @@ export class Repository {
21402153 args . push ( '--contains' , opts . contains ) ;
21412154 }
21422155
2143- const result = await this . exec ( args ) ;
2156+ const result = await this . exec ( args , { cancellationToken : opts ?. cancellationToken } ) ;
21442157
21452158 const fn = ( line : string ) : Ref | null => {
21462159 let match : RegExpExecArray | null ;
0 commit comments