Skip to content

Commit

Permalink
fix(merge): try to find missing commit from @semantic-release/git
Browse files Browse the repository at this point in the history
  • Loading branch information
kilianpaquier committed May 3, 2024
1 parent 59d5fc1 commit c6415f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/backmerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
13 changes: 4 additions & 9 deletions lib/git.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -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")).
Expand All @@ -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])
}

/**
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions test/backmerge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
actual = input
public async fetch(actualRemote: string): Promise<void> {
fetchRemote = actualRemote
}
public async ls(): Promise<string[]> {
public async ls(actualRemote: string): Promise<string[]> {
lsRemote = actualRemote
return ["develop", "staging"]
}
}
Expand All @@ -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"])
})

Expand Down

0 comments on commit c6415f6

Please sign in to comment.