@Test
  public void updateShouldNotMergeIfMultipleHeadsBeforeUpdate() throws Exception {
    changeFile_A_AndCommitInRemoteRepository();
    createAndCommitNewFileInLocalRepository();

    // create multiple heads locally
    HgUpdateCommand updateCommand = new HgUpdateCommand(myProject, projectRepoVirtualFile);
    HgRevisionNumber parent =
        new HgParentsCommand(myProject).execute(projectRepoVirtualFile).get(0);
    HgParentsCommand parentsCommand = new HgParentsCommand(myProject);
    parentsCommand.setRevision(parent);
    List<HgRevisionNumber> parents = parentsCommand.execute(projectRepoVirtualFile);
    updateCommand.setRevision(parents.get(0).getChangeset());
    updateCommand.execute();

    createFileInCommand(projectRepoVirtualFile.findChild("com"), "c.txt", "updated content");
    runHg(projectRepo, "commit", "-m", "creating new local head");

    List<HgRevisionNumber> branchHeads =
        new HgHeadsCommand(myProject, projectRepoVirtualFile).execute();
    assertEquals(branchHeads.size(), 2);

    HgRevisionNumber parentBeforeUpdate =
        new HgWorkingCopyRevisionsCommand(myProject).identify(projectRepoVirtualFile).getFirst();
    assertUpdateThroughPluginFails();
    HgRevisionNumber parentAfterUpdate =
        new HgWorkingCopyRevisionsCommand(myProject).identify(projectRepoVirtualFile).getFirst();
    List<HgRevisionNumber> branchHeadsAfterUpdate =
        new HgHeadsCommand(myProject, projectRepoVirtualFile).execute();

    assertEquals(branchHeadsAfterUpdate.size(), 3);
    assertEquals(parentBeforeUpdate, parentAfterUpdate);
  }
 private void assertCurrentHeadIsMerge(
     HgRevisionNumber incomingHead, HgRevisionNumber headBeforeUpdate) {
   List<HgRevisionNumber> newHeads =
       new HgHeadsCommand(myProject, projectRepoVirtualFile).execute();
   assertEquals(
       newHeads.size(),
       1,
       "After updating, there should be only one head because the remote heads should have been merged");
   HgRevisionNumber newHead = newHeads.get(0);
   HgParentsCommand parents = new HgParentsCommand(myProject);
   parents.setRevision(newHead);
   List<HgRevisionNumber> parentRevisions = parents.execute(projectRepoVirtualFile);
   assertEquals(parentRevisions.size(), 2);
   assertTrue(parentRevisions.contains(incomingHead));
   assertTrue(parentRevisions.contains(headBeforeUpdate));
 }