Skip to content

Commit

Permalink
feat(batch): try to re-clone repo if pull failed
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastrajan committed Mar 22, 2023
1 parent 93678b9 commit 83fd23f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/batch/tasks/init-job-repo.task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
pullLatest,
} from '../../services/git.service';
import { Context } from '../../interface';
import { directoryExists, pathJoin } from '../../services/fs.service';
import {
directoryExists,
pathJoin,
removeDirectoryRecursive,
} from '../../services/fs.service';

export function initJobRepo(job: string): ListrTask {
return {
Expand All @@ -19,8 +23,15 @@ export function initJobRepo(job: string): ListrTask {
await cloneRepo(job, workspacePath);
task.title = `${task.title}, cloned`;
} else {
await pullLatest(repoPath);
task.title = `${task.title}, updated`;
try {
await pullLatest(repoPath);
task.title = `${task.title}, updated`;
} catch (error) {
task.title = `${task.title}, git pull failed, remove and retry to clone`;
removeDirectoryRecursive(repoPath);
await cloneRepo(job, workspacePath);
task.title = `${task.title}, cloned`;
}
}
process.chdir(repoPath);
},
Expand Down

0 comments on commit 83fd23f

Please sign in to comment.