fix(repos): 修复在全新的工作目录中,检出指定commit时,找不到commit.
This commit is contained in:
@ -0,0 +1,2 @@
|
||||
import { ApplicationException } from '../../commons/exceptions/application.exception';
|
||||
export class GetWorkspaceLockFailedException extends ApplicationException {}
|
@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { Project } from '../projects/project.entity';
|
||||
import { ReposService } from './repos.service';
|
||||
import { ConfigService, ConfigModule } from '@nestjs/config';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { readFile, rm } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import configuration from '../commons/config/configuration';
|
||||
@ -50,9 +50,7 @@ describe('ReposService', () => {
|
||||
|
||||
await rm(service.getWorkspaceRoot(getTest1Project()), {
|
||||
recursive: true,
|
||||
}).catch((err) => {
|
||||
console.log('!!!!', err);
|
||||
});
|
||||
}).catch(() => undefined);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
@ -119,7 +117,7 @@ describe('ReposService', () => {
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/Commit 1/gi);
|
||||
});
|
||||
}, 20_000);
|
||||
it('should be checkout right commit', async () => {
|
||||
await service.checkoutCommit(getTest1Project(), '7f7123fe5b');
|
||||
const filePath = join(
|
||||
@ -128,6 +126,6 @@ describe('ReposService', () => {
|
||||
);
|
||||
const text = await readFile(filePath, { encoding: 'utf-8' });
|
||||
expect(text).toMatch(/(?!Commit 1)/gi);
|
||||
});
|
||||
}, 20_000);
|
||||
});
|
||||
});
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user