Skip to content

Commit

Permalink
Add force delete for local branches (#3)
Browse files Browse the repository at this point in the history
* Update local branch removal to force delete

* Update localBranchDeletionCallback test to use SimpleGit branch
  • Loading branch information
RichardMartinez authored Jan 26, 2019
1 parent 173866f commit 36dba54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/local-branches/localBranchDeletionCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
19 changes: 10 additions & 9 deletions tests/local-branches/localBranchDeletionCallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@ 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`)
})

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)
Expand Down

0 comments on commit 36dba54

Please sign in to comment.