Merge pull request #5729 from desktop/merge-abort-in-lib

add merge aborting functionality
This commit is contained in:
Brendan Forster 2018-10-14 16:34:19 -03:00 committed by GitHub
commit 45e7463884
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 6 deletions

View file

@ -80,3 +80,12 @@ export async function mergeTree(
return parseMergeResult(output)
}
/**
* Abort a mid-flight (conflicted) merge
*
* @param repository where to abort the merge
*/
export async function abortMerge(repository: Repository): Promise<void> {
await git(['merge', '--abort'], repository.path, 'abortMerge')
}

View file

@ -1,9 +1,8 @@
import { expect } from 'chai'
import { getMergeBase, getBranches } from '../../../src/lib/git'
import { abortMerge, getMergeBase, getBranches } from '../../../src/lib/git'
import {
setupEmptyRepository,
setupFixtureRepository,
setupConflictedRepo,
} from '../../helpers/repositories'
import { GitProcess } from 'dugite'
import { Repository } from '../../../src/models/repository'
@ -26,7 +25,7 @@ describe('git/merge', () => {
}
const ref = await getMergeBase(repository, first.tip.sha, second.tip.sha)
expect(ref).equals('df0d73dc92ff496c6a61f10843d527b7461703f4')
expect(ref).toEqual('df0d73dc92ff496c6a61f10843d527b7461703f4')
})
it('returns null when the branches do not have a common ancestor', async () => {
@ -65,7 +64,7 @@ describe('git/merge', () => {
}
const ref = await getMergeBase(repository, first.tip.sha, second.tip.sha)
expect(ref).is.null
expect(ref).toBeNull()
})
it('returns null when a ref cannot be found', async () => {
@ -82,7 +81,29 @@ describe('git/merge', () => {
'master',
'origin/some-unknown-branch'
)
expect(ref).is.null
expect(ref).toBeNull()
})
})
describe('abortMerge', () => {
let repository: Repository
const subject = () => abortMerge(repository)
describe('when there is no in-progress merge', () => {
beforeEach(async () => {
repository = await setupEmptyRepository()
})
it('throws an error', async () => {
await expect(subject()).rejects.toThrow(
/There is no merge in progress, so there is nothing to abort/
)
})
})
describe('in the middle of resolving conflicts merge', () => {
beforeEach(async () => {
repository = await setupConflictedRepo()
})
it('aborts the merge', async () => {
await expect(subject()).resolves.not.toThrow()
})
})
})
})