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 { ...@@ -161,12 +161,20 @@ export class AppService extends ConsoleLogger {
async checkoutCorrectBranch( async checkoutCorrectBranch(
forceNew?: boolean, forceNew?: boolean,
fetch?: boolean, fetch?: boolean,
newBranchOffset = 1,
): Promise<{ branchId: number; size: number }> { ): Promise<{ branchId: number; size: number }> {
const res = await this.getLatestBranchId(forceNew); const res = await this.getLatestBranchId(forceNew, newBranchOffset);
const branchName = res.branchId.toString(36); const branchName = res.branchId.toString(36);
if (!res.size) { if (!res.size) {
this.log(`Checking out to a new branch ${branchName}`); 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 { try {
await this.git.raw(['rm', '-rf', '.']); await this.git.raw(['rm', '-rf', '.']);
} catch (e) {} } catch (e) {}
...@@ -194,6 +202,7 @@ export class AppService extends ConsoleLogger { ...@@ -194,6 +202,7 @@ export class AppService extends ConsoleLogger {
async getLatestBranchId( async getLatestBranchId(
forceNew?: boolean, forceNew?: boolean,
newBranchOffset = 1,
): Promise<{ branchId: number; size: number }> { ): Promise<{ branchId: number; size: number }> {
const [latestFile] = await this.dbRepo.find({ const [latestFile] = await this.dbRepo.find({
select: ['branchId'], select: ['branchId'],
...@@ -201,11 +210,11 @@ export class AppService extends ConsoleLogger { ...@@ -201,11 +210,11 @@ export class AppService extends ConsoleLogger {
take: 1, take: 1,
}); });
if (!latestFile) { if (!latestFile) {
return { branchId: 1, size: 0 }; return { branchId: newBranchOffset, size: 0 };
} }
const branchId = parseInt(latestFile.branchIdValue.toString()); const branchId = parseInt(latestFile.branchIdValue.toString());
if (forceNew) { if (forceNew) {
return { branchId: branchId + 1, size: 0 }; return { branchId: branchId + newBranchOffset, size: 0 };
} }
const { totalSizeRaw } = await this.dbRepo const { totalSizeRaw } = await this.dbRepo
.createQueryBuilder('file') .createQueryBuilder('file')
...@@ -215,7 +224,7 @@ export class AppService extends ConsoleLogger { ...@@ -215,7 +224,7 @@ export class AppService extends ConsoleLogger {
const size = parseInt(totalSizeRaw); const size = parseInt(totalSizeRaw);
if (size >= this.maxBranchSize) { if (size >= this.maxBranchSize) {
this.log(`Will switch to branch ${branchId.toString(36)}`); this.log(`Will switch to branch ${branchId.toString(36)}`);
return { branchId: branchId + 1, size: 0 }; return { branchId: branchId + newBranchOffset, size: 0 };
} else { } else {
this.log(`Will remain on branch ${branchId.toString(36)}`); this.log(`Will remain on branch ${branchId.toString(36)}`);
return { branchId, size }; 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