diff --git a/src/apps/apps.service.ts b/src/apps/apps.service.ts index 2a5e26b..074f57c 100644 --- a/src/apps/apps.service.ts +++ b/src/apps/apps.service.ts @@ -702,6 +702,7 @@ export class AppsService { targetBranch, `origin/${targetBranch}`, ], { cwd: workDir }); + await this.resetPromotionWorktree(gitBin, workDir); try { await execFileAsync(gitBin, [ ...mergeOptions, @@ -715,6 +716,7 @@ export class AppsService { throw error; } try { + await this.resetPromotionWorktree(gitBin, workDir); await execFileAsync(gitBin, [ ...mergeOptions, 'merge', @@ -757,6 +759,7 @@ export class AppsService { commitSha: string, repository: string, ) { + await this.resetPromotionWorktree(gitBin, workDir); await execFileAsync(gitBin, [ ...mergeOptions, 'merge', @@ -771,6 +774,13 @@ export class AppsService { await execFileAsync(gitBin, ['commit', '--allow-empty', '-m', `${repository} release promotion merge`], { cwd: workDir }); } + private async resetPromotionWorktree(gitBin: string, workDir: string) { + await execFileAsync(gitBin, ['merge', '--abort'], { cwd: workDir }).catch(() => undefined); + await execFileAsync(gitBin, ['rebase', '--abort'], { cwd: workDir }).catch(() => undefined); + await execFileAsync(gitBin, ['reset', '--hard'], { cwd: workDir }).catch(() => undefined); + await execFileAsync(gitBin, ['clean', '-fd'], { cwd: workDir }).catch(() => undefined); + } + private getHttpCloneUrl(repository: string) { return `${this.configService .get('GITEA_BASE_URL', 'http://localhost:3000')