Search in sources :

Example 1 with HgRevertCommand

use of org.zmlx.hg4idea.command.HgRevertCommand in project intellij-community by JetBrains.

the class HgRevertUncommittedMergeTest method testRevertAfterMerge.

public void testRevertAfterMerge() throws VcsException {
    cd(myRepository);
    hg("branch branchA");
    String aFile = "A.txt";
    touch(aFile, "a");
    hg("add " + aFile);
    hg("commit -m 'create file in branchA' ");
    hg("up default");
    touch(aFile, "default");
    hg("add " + aFile);
    hg("commit -m 'create file in default branch'");
    hgMergeWith("branchA");
    HgCommandResult revertResult = new HgRevertCommand(myProject).execute(myRepository, Collections.singleton(new File(myRepository.getPath(), aFile).getAbsolutePath()), null, false);
    assertTrue(HgErrorUtil.hasUncommittedChangesConflict(revertResult));
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRevertCommand(org.zmlx.hg4idea.command.HgRevertCommand) File(java.io.File)

Example 2 with HgRevertCommand

use of org.zmlx.hg4idea.command.HgRevertCommand in project intellij-community by JetBrains.

the class HgRevertTest method testRevertToCurrentRevision.

@Test
public void testRevertToCurrentRevision() throws Exception {
    fillFile(myProjectDir, new String[] { "file.txt" }, "initial contents");
    runHgOnProjectRepo("add", ".");
    runHgOnProjectRepo("commit", "-m", "initial contents");
    fillFile(myProjectDir, new String[] { "file.txt" }, "new contents");
    HgRevertCommand revertCommand = new HgRevertCommand(myProject);
    revertCommand.execute(myRepo.getDir(), Collections.singleton(new File(myProjectDir, "file.txt").getPath()), null, false);
    HgCatCommand catCommand = new HgCatCommand(myProject);
    HgCommandResult result = catCommand.execute(getHgFile("file.txt"), null, Charset.defaultCharset());
    assertNotNull(result);
    assertEquals(result.getRawOutput(), "initial contents");
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCatCommand(org.zmlx.hg4idea.command.HgCatCommand) HgRevertCommand(org.zmlx.hg4idea.command.HgRevertCommand) File(java.io.File) Test(org.testng.annotations.Test)

Example 3 with HgRevertCommand

use of org.zmlx.hg4idea.command.HgRevertCommand in project intellij-community by JetBrains.

the class HgRevertTest method testRevertToGivenRevision.

@Test
public void testRevertToGivenRevision() throws Exception {
    fillFile(myProjectDir, new String[] { "file.txt" }, "initial contents");
    runHgOnProjectRepo("add", ".");
    runHgOnProjectRepo("commit", "-m", "initial contents");
    fillFile(myProjectDir, new String[] { "file.txt" }, "new contents");
    runHgOnProjectRepo("commit", "-m", "new contents");
    HgRevertCommand revertCommand = new HgRevertCommand(myProject);
    revertCommand.execute(myRepo.getDir(), Collections.singleton(new File(myProjectDir, "file.txt").getPath()), HgRevisionNumber.getLocalInstance("0"), false);
    HgCatCommand catCommand = new HgCatCommand(myProject);
    HgCommandResult result = catCommand.execute(getHgFile("file.txt"), HgRevisionNumber.getLocalInstance("0"), Charset.defaultCharset());
    assertNotNull(result);
    assertEquals(result.getRawOutput(), "initial contents");
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgCatCommand(org.zmlx.hg4idea.command.HgCatCommand) HgRevertCommand(org.zmlx.hg4idea.command.HgRevertCommand) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with HgRevertCommand

use of org.zmlx.hg4idea.command.HgRevertCommand in project intellij-community by JetBrains.

the class HgRollbackEnvironment method revert.

private void revert(@NotNull List<FilePath> filePaths) {
    for (Map.Entry<VirtualFile, Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(project, filePaths).entrySet()) {
        final VirtualFile repo = entry.getKey();
        final Collection<FilePath> files = entry.getValue();
        HgRevisionNumber revisionNumber = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
        for (List<String> chunk : VcsFileUtil.chunkPaths(repo, files)) {
            HgCommandResult revertResult = new HgRevertCommand(project).execute(repo, chunk, revisionNumber, false);
            if (HgErrorUtil.hasUncommittedChangesConflict(revertResult)) {
                String message = String.format("<html>Revert failed due to uncommitted merge.<br>" + "Would you like to discard all changes for repository <it><b>%s</b></it>?</html>", repo.getPresentableName());
                int exitCode = HgUpdateCommand.showDiscardChangesConfirmation(project, message);
                if (exitCode == Messages.OK) {
                    //discard all changes for this repository//
                    HgUpdateCommand updateCommand = new HgUpdateCommand(project, repo);
                    updateCommand.setClean(true);
                    updateCommand.setRevision(".");
                    updateCommand.execute();
                }
                break;
            }
            new HgResolveCommand(project).markResolved(repo, files);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) HgResolveCommand(org.zmlx.hg4idea.command.HgResolveCommand) HgWorkingCopyRevisionsCommand(org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand) HgRevertCommand(org.zmlx.hg4idea.command.HgRevertCommand) HgUpdateCommand(org.zmlx.hg4idea.command.HgUpdateCommand) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Aggregations

HgRevertCommand (org.zmlx.hg4idea.command.HgRevertCommand)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 File (java.io.File)3 Test (org.testng.annotations.Test)2 HgCatCommand (org.zmlx.hg4idea.command.HgCatCommand)2 FilePath (com.intellij.openapi.vcs.FilePath)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)1 HgResolveCommand (org.zmlx.hg4idea.command.HgResolveCommand)1 HgUpdateCommand (org.zmlx.hg4idea.command.HgUpdateCommand)1 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)1