@@ -20,7 +20,7 @@ function trimTrailingNewline(str: string): string {
2020}
2121
2222export function git ( args : string [ ] , options ?: IGitOptions ) : Promise < string > {
23- const workDir = options && options . workDir || "." ;
23+ const workDir = ( options && options . workDir ) || "." ;
2424 if ( options && options . trace ) {
2525 process . stderr . write ( `Called 'git ${ args . join ( " " ) } ' in '${ workDir } ':\n${ new Error ( ) . stack } \n` ) ;
2626 }
@@ -83,31 +83,43 @@ export function git(args: string[], options?: IGitOptions): Promise<string> {
8383 handleLine ( buffer ) ;
8484 }
8585 if ( linePromise ) {
86- linePromise . then ( ( ) => { resolve ( "" ) ; } )
87- . catch ( ( reason ) => { reject ( reason as Error ) ; } ) ;
86+ linePromise
87+ . then ( ( ) => {
88+ resolve ( "" ) ;
89+ } )
90+ . catch ( ( reason ) => {
91+ reject ( reason as Error ) ;
92+ } ) ;
8893 } else {
8994 resolve ( "" ) ;
9095 }
9196 } ) ;
9297 } ;
9398 }
9499
95- GitProcess . exec ( args , workDir , options as IGitExecutionOptions ) . then ( ( result ) => {
96- if ( result . exitCode ) {
97- reject ( new Error ( `git ${ args . join ( " " ) } failed: ${ result . exitCode } ,\n${ result . stderr } ` ) ) ;
98- return ;
99- }
100- if ( options && options . trace ) {
101- process . stderr . write ( `Output of 'git ${ args . join ( " " ) } ':\nstderr: ${ result . stderr } \nstdout: ${
102- result . stdout } \n`) ;
103- }
104- if ( ! options ?. lineHandler ) { // let callback resolve the promise
105- resolve ( ! options || options . trimTrailingNewline === false ?
106- result . stdout : trimTrailingNewline ( result . stdout ) ) ;
107- }
108- } ) . catch ( ( reason ) => {
109- reject ( reason as Error ) ;
110- } ) ;
100+ GitProcess . exec ( args , workDir , options as IGitExecutionOptions )
101+ . then ( ( result ) => {
102+ if ( result . exitCode ) {
103+ reject ( new Error ( `git ${ args . join ( " " ) } failed: ${ result . exitCode } ,\n${ result . stderr } ` ) ) ;
104+ return ;
105+ }
106+ if ( options && options . trace ) {
107+ process . stderr . write (
108+ `Output of 'git ${ args . join ( " " ) } ':\nstderr: ${ result . stderr } \nstdout: ${ result . stdout } \n` ,
109+ ) ;
110+ }
111+ if ( ! options ?. lineHandler ) {
112+ // let callback resolve the promise
113+ resolve (
114+ ! options || options . trimTrailingNewline === false
115+ ? result . stdout
116+ : trimTrailingNewline ( result . stdout ) ,
117+ ) ;
118+ }
119+ } )
120+ . catch ( ( reason ) => {
121+ reject ( reason as Error ) ;
122+ } ) ;
111123 } ) ;
112124}
113125
@@ -138,15 +150,14 @@ export async function revParse(argument: string, workDir?: string): Promise<stri
138150 */
139151export async function revListCount ( rangeArgs : string | string [ ] , workDir = "." ) : Promise < number > {
140152 const gitArgs : string [ ] = [ "rev-list" , "--count" ] ;
141- if ( typeof ( rangeArgs ) === "string" ) {
153+ if ( typeof rangeArgs === "string" ) {
142154 gitArgs . push ( rangeArgs ) ;
143155 } else {
144156 gitArgs . push ( ...rangeArgs ) ;
145157 }
146158 const result = await GitProcess . exec ( gitArgs , workDir ) ;
147159 if ( result . exitCode ) {
148- throw new Error ( `Could not determine count for ${
149- rangeArgs } : ${ result . stderr } `) ;
160+ throw new Error ( `Could not determine count for ${ rangeArgs } : ${ result . stderr } ` ) ;
150161 }
151162 return parseInt ( result . stdout , 10 ) ;
152163}
@@ -159,7 +170,7 @@ export async function revListCount(rangeArgs: string | string[], workDir = "."):
159170 * @returns {boolean } whether the commit exists
160171 */
161172export async function commitExists ( commit : string , workDir : string ) : Promise < boolean > {
162- return await revParse ( `${ commit } ^{commit}` , workDir ) !== undefined ;
173+ return ( await revParse ( `${ commit } ^{commit}` , workDir ) ) !== undefined ;
163174}
164175
165176export async function gitConfig ( key : string , workDir ?: string ) : Promise < string | undefined > {
@@ -170,10 +181,11 @@ export async function gitConfig(key: string, workDir?: string): Promise<string |
170181 return trimTrailingNewline ( result . stdout ) ;
171182}
172183
173- export async function gitConfigForEach ( key : string ,
174- callbackfn : ( value : string ) => void ,
175- workDir ?: string ) :
176- Promise < void > {
184+ export async function gitConfigForEach (
185+ key : string ,
186+ callbackfn : ( value : string ) => void ,
187+ workDir ?: string ,
188+ ) : Promise < void > {
177189 const result = await GitProcess . exec ( [ "config" , "--get-all" , key ] , workDir || "." ) ;
178190 result . stdout . split ( / \r ? \n / ) . map ( callbackfn ) ;
179191}
0 commit comments