IDEA-83415 git: do not allow to commit if repository has unmerged files

We could've silently override conflicts during `resetExcluded`/`restoreExcluded` routine before.
This commit is contained in:
Aleksey Pivovarov
2018-07-19 15:14:19 +03:00
parent 3e1f2efb13
commit bfdab13dca
2 changed files with 36 additions and 0 deletions
@@ -288,6 +288,11 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
VirtualFile root = repository.getRoot();
String rootPath = root.getPath();
List<File> 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<Change> stagedChanges = GitChangeUtils.getStagedChanges(myProject, root);
LOG.debug("Found staged changes: " + GitUtil.getLogString(rootPath, stagedChanges));
@@ -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)))