From 36dba54db0d3e7da9bf61d216e80025a4bb9cb8e Mon Sep 17 00:00:00 2001 From: Rich Martinez Date: Sat, 26 Jan 2019 10:43:25 -0500 Subject: [PATCH] Add force delete for local branches (#3) * Update local branch removal to force delete * Update localBranchDeletionCallback test to use SimpleGit branch --- .../localBranchDeletionCallback.js | 2 +- .../localBranchDeletionCallback.test.js | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/local-branches/localBranchDeletionCallback.js b/src/local-branches/localBranchDeletionCallback.js index 3ee15d6..3f86e65 100644 --- a/src/local-branches/localBranchDeletionCallback.js +++ b/src/local-branches/localBranchDeletionCallback.js @@ -7,7 +7,7 @@ const simpleGit = require('simple-git/promise') exports.localBranchDeletionCallback = async (branch) => { let successfullyRemovedBranch - await simpleGit().deleteLocalBranch(branch) + await simpleGit().branch(['-D', branch]) .then(({ branch }) => { successfullyRemovedBranch = branch console.log(`\n"${successfullyRemovedBranch}" was successfully removed.\n`) diff --git a/tests/local-branches/localBranchDeletionCallback.test.js b/tests/local-branches/localBranchDeletionCallback.test.js index f439859..deac84a 100644 --- a/tests/local-branches/localBranchDeletionCallback.test.js +++ b/tests/local-branches/localBranchDeletionCallback.test.js @@ -9,19 +9,20 @@ global.console = { } const branchName = 'test' +const simpleGitBranchOptions = ['-D', branchName] test('The branch was successfully removed', async () => { // const consoleError = 'Something went wrong with deleting the branch'; - const simpleGitDeleteLocalBranch = jest.fn((branch) => { - return Promise.resolve({ branch, success: true }) + const simpleGitBranch = jest.fn((options) => { + return Promise.resolve({ branch: branchName }) }) - simpleGit.mockReturnValue({ deleteLocalBranch: simpleGitDeleteLocalBranch }) + simpleGit.mockReturnValue({ branch: simpleGitBranch }) const removedBranch = await localBranchDeletionCallback(branchName) expect(simpleGit).toBeCalledTimes(1) - expect(simpleGitDeleteLocalBranch).toBeCalledTimes(1) - expect(simpleGitDeleteLocalBranch).toBeCalledWith(branchName) + expect(simpleGitBranch).toBeCalledTimes(1) + expect(simpleGitBranch).toBeCalledWith(simpleGitBranchOptions) expect(removedBranch).toEqual(branchName) expect(console.log).toBeCalledTimes(1) expect(console.log).toBeCalledWith(`\n"test" was successfully removed.\n`) @@ -29,16 +30,16 @@ test('The branch was successfully removed', async () => { test('Deleting a local branch promise is rejected.', async () => { const consoleError = 'Something went wrong with deleting the branch' - const simpleGitDeleteLocalBranch = jest.fn((branch) => { + const simpleGitBranch = jest.fn((options) => { return Promise.reject(consoleError) }) - simpleGit.mockReturnValue({ deleteLocalBranch: simpleGitDeleteLocalBranch }) + simpleGit.mockReturnValue({ branch: simpleGitBranch }) const removedBranch = await localBranchDeletionCallback(branchName) expect(simpleGit).toBeCalledTimes(1) - expect(simpleGitDeleteLocalBranch).toBeCalledTimes(1) - expect(simpleGitDeleteLocalBranch).toBeCalledWith(branchName) + expect(simpleGitBranch).toBeCalledTimes(1) + expect(simpleGitBranch).toBeCalledWith(simpleGitBranchOptions) expect(removedBranch).toEqual(undefined) expect(console.error).toBeCalledTimes(1) expect(console.error).toBeCalledWith(consoleError)