Skip to content

Commit

Permalink
chore(merge): remove useless reset hard before opening pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
kilianpaquier committed May 4, 2024
1 parent f698d5b commit 912e1e7
Showing 2 changed files with 0 additions and 46 deletions.
8 changes: 0 additions & 8 deletions lib/git.ts
Original file line number Diff line number Diff line change
@@ -143,14 +143,6 @@ export const mergeBranch = async (context: Partial<VerifyConditionsContext>, con
await git(push, options)
} catch (pushError) {
context.logger?.error(`Failed to backmerge '${from}' into '${to}' with a push, opening pull request.`, pushError)

try {
// reset hard in case a merge commit had been done just previous steps
await git(["reset", "--hard", `${remote}/${from}`], options)
} catch (resetError) {
return new SemanticReleaseError(`Failed to reset branch '${from}' to '${remote}' state before opening pull request.`, "ERESETHARD", String(resetError))
}

if (config.dryRun) {
context.logger?.log(`Running with --dry-run, created pull request would have been from '${from}' into '${to}' with title '${commit}'.`)
return Promise.resolve()
38 changes: 0 additions & 38 deletions test/git.test.ts
Original file line number Diff line number Diff line change
@@ -160,44 +160,6 @@ describe("mergeBranch", () => {
expect(logSpy).toHaveBeenCalledTimes(1)
})

test("should be fine at git merge, fail at push with dry run and fail at reset hard", async () => {
// Arrange
gitSpy.mockImplementationOnce(() => Promise.resolve(defaultExeca({}))) // checkout
gitSpy.mockImplementationOnce(() => Promise.resolve(defaultExeca({}))) // merge
gitSpy.mockImplementationOnce(() => Promise.reject(new Error("an error message"))) // push
gitSpy.mockImplementationOnce(() => Promise.reject(new Error("an error message"))) // reset hard

const config = ensureDefault({ dryRun: true })

// Act
const error = await git.mergeBranch(context, config, info, "main", "develop")

// Assert
expect(error?.code).toEqual("ERESETHARD")
expect(gitSpy).toHaveBeenCalledTimes(4)
expect(prSpy).not.toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledTimes(2)
})

test("should be fine at git merge, fail at push with dry run but be fine at hard reset", async () => {
// Arrange
gitSpy.mockImplementationOnce(() => Promise.resolve(defaultExeca({}))) // checkout
gitSpy.mockImplementationOnce(() => Promise.resolve(defaultExeca({}))) // merge
gitSpy.mockImplementationOnce(() => Promise.reject(new Error("an error message"))) // push
gitSpy.mockImplementationOnce(() => Promise.resolve(defaultExeca({}))) // reset hard

const config = ensureDefault({ dryRun: true })

// Act
const error = await git.mergeBranch(context, config, info, "main", "develop")

// Assert
expect(error).toBeUndefined()
expect(gitSpy).toHaveBeenCalledTimes(4)
expect(prSpy).not.toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledTimes(3)
})

test("should be fine at git merge, fail at push and create pull request", async () => {
// Arrange
gitSpy.mockImplementationOnce(() => Promise.resolve(defaultExeca({}))) // checkout

0 comments on commit 912e1e7

Please sign in to comment.