Commit 5b1da499 authored by nanahira's avatar nanahira

fix checkout

parent 5b7c8ea7
Pipeline #5446 passed with stages
in 8 minutes and 38 seconds
......@@ -161,12 +161,20 @@ export class AppService extends ConsoleLogger {
async checkoutCorrectBranch(
forceNew?: boolean,
fetch?: boolean,
newBranchOffset = 1,
): Promise<{ branchId: number; size: number }> {
const res = await this.getLatestBranchId(forceNew);
const res = await this.getLatestBranchId(forceNew, newBranchOffset);
const branchName = res.branchId.toString(36);
if (!res.size) {
this.log(`Checking out to a new branch ${branchName}`);
await this.git.checkout(['--orphan', branchName]);
try {
await this.git.checkout(['--orphan', branchName]);
} catch (e) {
this.error(
`Failed checking out to new branch ${branchName}, would retry with another branch: ${e.toString()}`,
);
return this.checkoutCorrectBranch(true, fetch, newBranchOffset + 1)
}
try {
await this.git.raw(['rm', '-rf', '.']);
} catch (e) {}
......@@ -194,6 +202,7 @@ export class AppService extends ConsoleLogger {
async getLatestBranchId(
forceNew?: boolean,
newBranchOffset = 1,
): Promise<{ branchId: number; size: number }> {
const [latestFile] = await this.dbRepo.find({
select: ['branchId'],
......@@ -201,11 +210,11 @@ export class AppService extends ConsoleLogger {
take: 1,
});
if (!latestFile) {
return { branchId: 1, size: 0 };
return { branchId: newBranchOffset, size: 0 };
}
const branchId = parseInt(latestFile.branchIdValue.toString());
if (forceNew) {
return { branchId: branchId + 1, size: 0 };
return { branchId: branchId + newBranchOffset, size: 0 };
}
const { totalSizeRaw } = await this.dbRepo
.createQueryBuilder('file')
......@@ -215,7 +224,7 @@ export class AppService extends ConsoleLogger {
const size = parseInt(totalSizeRaw);
if (size >= this.maxBranchSize) {
this.log(`Will switch to branch ${branchId.toString(36)}`);
return { branchId: branchId + 1, size: 0 };
return { branchId: branchId + newBranchOffset, size: 0 };
} else {
this.log(`Will remain on branch ${branchId.toString(36)}`);
return { branchId, size };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment