From d695ad47cfae17793db8f5f489904417819a7e84 Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Sun, 18 Jul 2021 20:49:23 +0200 Subject: [PATCH] fix: checkout with -B (#21) -B option will create the new branch if it does not exist, or reset an existing branch. --- src/helpers/git.ts | 2 +- test/helpers/git.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/git.ts b/src/helpers/git.ts index b0120e1..282325a 100644 --- a/src/helpers/git.ts +++ b/src/helpers/git.ts @@ -107,7 +107,7 @@ export default class Git { * @throws {Error} if the checkout failed. */ async checkout(branch: string) { - await execa('git', ['checkout', branch], this.execaOpts); + await execa('git', ['checkout', '-B', branch], this.execaOpts); } /** diff --git a/test/helpers/git.test.ts b/test/helpers/git.test.ts index a4a6991..2137d2d 100644 --- a/test/helpers/git.test.ts +++ b/test/helpers/git.test.ts @@ -87,7 +87,7 @@ describe("git", () => { await subject.checkout('develop'); expect(execa).toHaveBeenCalledWith( 'git', - ['checkout', 'develop'], + ['checkout', '-B', 'develop'], expect.objectContaining(execaOpts) ); });