@@ -10,15 +10,13 @@ const pushActionChain: ((req: any, action: Action) => Promise<Action>)[] = [
1010 proc . push . checkCommitMessages ,
1111 proc . push . checkAuthorEmails ,
1212 proc . push . checkUserPushPermission ,
13- proc . push . pullRemote ,
13+ proc . push . pullRemote , // cleanup is handled after chain execution if successful
1414 proc . push . writePack ,
1515 proc . push . checkHiddenCommits ,
1616 proc . push . checkIfWaitingAuth ,
1717 proc . push . preReceive ,
1818 proc . push . getDiff ,
19- // run before clear remote
2019 proc . push . gitleaks ,
21- proc . push . clearBareClone ,
2220 proc . push . scanDiff ,
2321 proc . push . blockForAuth ,
2422] ;
@@ -35,6 +33,7 @@ let pluginsInserted = false;
3533
3634export const executeChain = async ( req : any , res : any ) : Promise < Action > => {
3735 let action : Action = { } as Action ;
36+ let checkoutCleanUpRequired = false ;
3837
3938 try {
4039 action = await proc . pre . parseAction ( req ) ;
@@ -44,18 +43,28 @@ export const executeChain = async (req: any, res: any): Promise<Action> => {
4443 action = await fn ( req , action ) ;
4544 if ( ! action . continue ( ) || action . allowPush ) {
4645 break ;
46+ } else if ( fn === proc . push . pullRemote ) {
47+ //if the pull was successful then record the fact we need to clean it up again
48+ // pullRemote should cleanup unsuccessful clones itself
49+ checkoutCleanUpRequired = true ;
4750 }
4851 }
4952 } catch ( e ) {
5053 action . error = true ;
5154 action . errorMessage = `An error occurred when executing the chain: ${ e } ` ;
5255 console . error ( action . errorMessage ) ;
5356 } finally {
54- await proc . push . audit ( req , action ) ;
57+ //clean up the clone created
58+ if ( checkoutCleanUpRequired ) {
59+ action = await proc . post . clearBareClone ( req , action ) ;
60+ }
61+
62+ action = await proc . post . audit ( req , action ) ;
63+
5564 if ( action . autoApproved ) {
56- attemptAutoApproval ( action ) ;
65+ await attemptAutoApproval ( action ) ;
5766 } else if ( action . autoRejected ) {
58- attemptAutoRejection ( action ) ;
67+ await attemptAutoRejection ( action ) ;
5968 }
6069 }
6170
0 commit comments