@@ -198,7 +198,7 @@ async function exec(child: cp.ChildProcess, cancellationToken?: CancellationToke
198
198
}
199
199
200
200
if ( cancellationToken && cancellationToken . isCancellationRequested ) {
201
- throw new GitError ( { message : 'Cancelled' } ) ;
201
+ throw new CancellationError ( ) ;
202
202
}
203
203
204
204
const disposables : IDisposable [ ] = [ ] ;
@@ -239,7 +239,7 @@ async function exec(child: cp.ChildProcess, cancellationToken?: CancellationToke
239
239
// noop
240
240
}
241
241
242
- e ( new GitError ( { message : 'Cancelled' } ) ) ;
242
+ e ( new CancellationError ( ) ) ;
243
243
} ) ;
244
244
} ) ;
245
245
@@ -568,12 +568,21 @@ export class Git {
568
568
}
569
569
570
570
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
+ }
573
582
574
583
if ( options . log !== false ) {
575
584
// command
576
- this . log ( `> git ${ args . join ( ' ' ) } [${ durExec } ms]\n` ) ;
585
+ this . log ( `> git ${ args . join ( ' ' ) } [${ Date . now ( ) - startExec } ms]\n` ) ;
577
586
578
587
// stdout
579
588
if ( bufferResult . stdout . length > 0 && args . find ( a => this . commandsToLog . includes ( a ) ) ) {
@@ -2119,7 +2128,11 @@ export class Repository {
2119
2128
. map ( ( [ ref ] ) => ( { name : ref , type : RefType . Head } as Branch ) ) ;
2120
2129
}
2121
2130
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
+
2123
2136
const args = [ 'for-each-ref' ] ;
2124
2137
2125
2138
if ( opts ?. count ) {
@@ -2140,7 +2153,7 @@ export class Repository {
2140
2153
args . push ( '--contains' , opts . contains ) ;
2141
2154
}
2142
2155
2143
- const result = await this . exec ( args ) ;
2156
+ const result = await this . exec ( args , { cancellationToken : opts ?. cancellationToken } ) ;
2144
2157
2145
2158
const fn = ( line : string ) : Ref | null => {
2146
2159
let match : RegExpExecArray | null ;
0 commit comments