From 912e1e7863cdad62156a692288e06d0164eade5f Mon Sep 17 00:00:00 2001 From: Kilian PAQUIER Date: Thu, 2 May 2024 21:20:20 +0000 Subject: [PATCH] chore(merge): remove useless reset hard before opening pull request --- lib/git.ts | 8 -------- test/git.test.ts | 38 -------------------------------------- 2 files changed, 46 deletions(-) diff --git a/lib/git.ts b/lib/git.ts index 62a43b2..5082db3 100644 --- a/lib/git.ts +++ b/lib/git.ts @@ -143,14 +143,6 @@ export const mergeBranch = async (context: Partial, 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() diff --git a/test/git.test.ts b/test/git.test.ts index 5d4bbdd..1a1a821 100644 --- a/test/git.test.ts +++ b/test/git.test.ts @@ -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