From c6415f6e040c54e8122a9b0a90f1b588e3b55bba Mon Sep 17 00:00:00 2001 From: Kilian PAQUIER Date: Fri, 3 May 2024 20:39:49 +0000 Subject: [PATCH] fix(merge): try to find missing commit from @semantic-release/git --- lib/backmerge.ts | 4 ++-- lib/git.ts | 13 ++++--------- test/backmerge.test.ts | 13 ++++++++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/backmerge.ts b/lib/backmerge.ts index 4afe2c5..df164a9 100644 --- a/lib/backmerge.ts +++ b/lib/backmerge.ts @@ -44,12 +44,12 @@ export const getBranches = async (context: Context, remote: string, targets: Tar context.logger.log(`Current branch '${releaseBranch}' doesn't match any configured backmerge targets.`) return [] } - context.logger.log(`Current branch '${releaseBranch}' matches following configured backmerge targets: '${JSON.stringify(targets)}'. Performing backmerge.`) + context.logger.log(`Current branch '${releaseBranch}' matches following configured backmerge targets: '${JSON.stringify(appropriates)}'. Performing backmerge.`) const git = new Git(context.cwd, context.env) await git.fetch(remote) - const branches = (await git.ls()). + const branches = (await git.ls(remote)). // don't keep the released branch filter(branch => releaseBranch !== branch). diff --git a/lib/git.ts b/lib/git.ts index d11adac..193f1dc 100644 --- a/lib/git.ts +++ b/lib/git.ts @@ -1,10 +1,5 @@ import { Options, execa } from "execa" -/** - * remote is the string representing git remote name. - */ -const origin = "origin" - /** * Git is the class for all related git actions. */ @@ -48,8 +43,8 @@ export class Git { * * @throws an error is the git ls-remote cannot be done. */ - public async ls() { - const response = await this.exec(["ls-remote", "--heads", origin]) + public async ls(remote: string) { + const response = await this.exec(["ls-remote", "--heads", remote]) const branches = response.stdout.toString(). split("\n"). map(branch => branch.split("\t")). @@ -68,7 +63,7 @@ export class Git { * @throws an error if the checkout cannot be done. */ public async checkout(branch: string) { - await this.exec(["checkout", "-B", branch, `${origin}/${branch}`]) + await this.exec(["checkout", "-b", branch]) } /** @@ -96,7 +91,7 @@ export class Git { await this.checkout(to) try { - await this.exec(["merge", `${origin}/${from}`, "--ff", "-m", commit]) + await this.exec(["merge", `${from}`, "--ff", "-m", commit]) } catch (error) { await this.exec(["merge", "--abort"]) throw error diff --git a/test/backmerge.test.ts b/test/backmerge.test.ts index a9b49de..fe23fe6 100644 --- a/test/backmerge.test.ts +++ b/test/backmerge.test.ts @@ -91,13 +91,15 @@ describe("getBranches", () => { test("should retrieve some branches", async () => { // Arrange - let actual = "" + let fetchRemote = "" + let lsRemote = "" await mock.module("../lib/git", () => ({ Git: class MockGit extends Git { - public async fetch(input: string): Promise { - actual = input + public async fetch(actualRemote: string): Promise { + fetchRemote = actualRemote } - public async ls(): Promise { + public async ls(actualRemote: string): Promise { + lsRemote = actualRemote return ["develop", "staging"] } } @@ -108,7 +110,8 @@ describe("getBranches", () => { const branches = await getBranches(context, remote, [{ from: "main", to: "(develop|staging)" }]) // Assert - expect(actual).toEqual(remote) + expect(fetchRemote).toEqual(remote) + expect(lsRemote).toEqual(remote) expect(branches).toEqual(["develop", "staging"]) })