55 cloneRepo ,
66 pullLatest ,
77} from '../../services/git.service' ;
8+ import { wait } from '../../utils/wait' ;
89import { Context } from '../../interface' ;
910import {
1011 directoryExists ,
@@ -19,21 +20,26 @@ export function initJobRepo(job: string): ListrTask {
1920 const { workspacePath, verbose } = ctx . options ;
2021 const repoName = getRepoNameFromUrl ( job ) ;
2122 const repoPath = pathJoin ( workspacePath , repoName ) ;
22- if ( ! directoryExists ( repoPath ) ) {
23- await cloneRepo ( job , workspacePath ) ;
24- task . title = `${ task . title } , cloned` ;
25- } else {
26- try {
27- await pullLatest ( repoPath ) ;
28- task . title = `${ task . title } , updated` ;
29- } catch ( error ) {
30- task . title = `${ task . title } , git pull failed, remove and retry to clone` ;
31- removeDirectoryRecursive ( repoPath ) ;
23+ try {
24+ if ( ! directoryExists ( repoPath ) ) {
3225 await cloneRepo ( job , workspacePath ) ;
3326 task . title = `${ task . title } , cloned` ;
27+ } else {
28+ try {
29+ await pullLatest ( repoPath ) ;
30+ task . title = `${ task . title } , updated` ;
31+ } catch ( error ) {
32+ task . title = `${ task . title } , git pull failed, remove and retry to clone` ;
33+ removeDirectoryRecursive ( repoPath ) ;
34+ await cloneRepo ( job , workspacePath ) ;
35+ task . title = `${ task . title } , cloned` ;
36+ }
3437 }
38+ process . chdir ( repoPath ) ;
39+ } catch ( error : any ) {
40+ await wait ( ) ;
41+ throw new error ( ) ;
3542 }
36- process . chdir ( repoPath ) ;
3743 } ,
3844 } ;
3945}
0 commit comments