diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index c7d84607099c..ab82e742b90f 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -288,6 +288,11 @@ public class GitCheckinEnvironment implements CheckinEnvironment { VirtualFile root = repository.getRoot(); String rootPath = root.getPath(); + List unmergedFiles = GitChangeUtils.getUnmergedFiles(repository); + if (!unmergedFiles.isEmpty()) { + throw new VcsException("Committing is not possible because you have unmerged files."); + } + // Check what is staged besides our changes Collection stagedChanges = GitChangeUtils.getStagedChanges(myProject, root); LOG.debug("Found staged changes: " + GitUtil.getLogString(rootPath, stagedChanges)); diff --git a/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt b/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt index 540de88483a5..a43c4330e744 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt +++ b/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt @@ -570,6 +570,37 @@ abstract class GitCommitTest(private val useStagingArea: Boolean) : GitSingleRep } } + fun `test commit during unresolved merge conflict`() { + `assume version where git reset returns 0 exit code on success `() + assumeTrue(Registry.`is`("git.force.commit.using.staging.area")) // "--only" shows dialog in this case + + createFileStructure(projectRoot, "a.txt") + addCommit("created some file structure") + + git("branch feature") + + val file = File(projectPath, "a.txt") + assertTrue("File doesn't exist!", file.exists()) + overwrite(file, "my content") + addCommit("modified in master") + + checkout("feature") + overwrite(file, "brother content") + addCommit("modified in feature") + + checkout("master") + git("merge feature", true) // ignoring non-zero exit-code reporting about conflicts + + updateChangeListManager() + val changes = changeListManager.allChanges + assertTrue(!changes.isEmpty()) + + val exceptions = vcs.checkinEnvironment!!.commit(ArrayList(changes), "comment") + assertTrue(exceptions!!.isNotEmpty()) + + assertMessage("modified in master", repo.message("HEAD")) + } + private fun `assume version where git reset returns 0 exit code on success `() { assumeTrue("Not testing: git reset returns 1 and fails the commit process in ${vcs.version}", vcs.version.isLaterOrEqual(GitVersion(1, 8, 2, 0)))