@@ -45,20 +45,10 @@ export function git(args: string[], options?: IGitOptions | undefined):
4545 if ( ! process . stdout ) {
4646 throw new Error ( `No stdout for "git ${ args . join ( " " ) } ` ) ;
4747 }
48- let linePromise : Promise < void > | undefined ;
48+ const promises : Array < Promise < void > > = [ ] ;
4949 const handleLine = ( line : string ) : boolean => {
5050 try {
51- if ( ! linePromise ) {
52- linePromise = lineHandler ( line ) ;
53- } else {
54- linePromise = linePromise . then ( ( ) => {
55- return lineHandler ( line ) ;
56- } ) ;
57- }
58- linePromise . catch ( ( reason ) => {
59- reject ( reason ) ;
60- process . kill ( ) ;
61- } ) ;
51+ promises . push ( lineHandler ( line ) ) ;
6252 } catch ( reason ) {
6353 reject ( reason ) ;
6454 process . kill ( ) ;
@@ -84,12 +74,7 @@ export function git(args: string[], options?: IGitOptions | undefined):
8474 if ( buffer . length > 0 ) {
8575 handleLine ( buffer ) ;
8676 }
87- if ( linePromise ) {
88- linePromise . then ( ( ) => { resolve ( "" ) ; } )
89- . catch ( ( reason ) => { reject ( reason ) ; } ) ;
90- } else {
91- resolve ( "" ) ;
92- }
77+ Promise . all ( promises ) . then ( ( ) => resolve ( "" ) ) . catch ( reject ) ;
9378 } ) ;
9479 } ;
9580 }
@@ -107,8 +92,10 @@ export function git(args: string[], options?: IGitOptions | undefined):
10792 } ':\nstderr: ${ result . stderr
10893 } \nstdout: ${ result . stdout } \n`) ;
10994 }
110- resolve ( ! options || options . trimTrailingNewline === false ?
111- result . stdout : trimTrailingNewline ( result . stdout ) ) ;
95+ if ( ! options ?. lineHandler ) { // let callback resolve the promise
96+ resolve ( ! options || options . trimTrailingNewline === false ?
97+ result . stdout : trimTrailingNewline ( result . stdout ) ) ;
98+ }
11299 } ) . catch ( ( reason ) => {
113100 reject ( reason ) ;
114101 } ) ;
0 commit comments