fix(repos): 修复在全新的工作目录中,检出指定commit时,找不到commit.

This commit is contained in:
Ivan
2021-02-25 15:36:13 +08:00
parent 90d851d85c
commit 5b2a017858
5 changed files with 527 additions and 10 deletions

View File

@@ -26,8 +26,14 @@ export class ReposService {
);
}
async lockWorkspace(workspaceRoot: string) {
// TODO: 获取锁,失败抛错。
}
async getGit(project: Project) {
const workspaceRoot = this.getWorkspaceRoot(project);
await this.lockWorkspace(workspaceRoot);
const firstInit = await access(workspaceRoot, F_OK)
.then(() => false)
.catch(async () => {
@@ -83,12 +89,13 @@ export class ReposService {
async checkoutCommit(project: Project, commitNumber: string) {
const git = await this.getGit(project);
try {
await git.checkout([commitNumber]);
await git.fetch(DEFAULT_REMOTE_NAME);
} catch (err) {
if (err.message.includes("couldn't find remote ref nonexistent")) {
throw new NotFoundException(err.message);
}
throw err;
}
await git.checkout([commitNumber]);
}
}