Search in sources :

Example 31 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class HgHistoryUtil method history.

/**
   * <p>Get & parse hg log detailed output with commits, their parents and their changes.
   * For null destination return log command result</p>
   * <p/>
   * <p>Warning: this is method is efficient by speed, but don't query too much, because the whole log output is retrieved at once,
   * and it can occupy too much memory. The estimate is ~600Kb for 1000 commits.</p>
   */
@NotNull
public static List<? extends VcsFullCommitDetails> history(@NotNull final Project project, @NotNull final VirtualFile root, final int limit, @NotNull List<String> hashParameters, final boolean silent) throws VcsException {
    HgVcs hgvcs = HgVcs.getInstance(project);
    assert hgvcs != null;
    final HgVersion version = hgvcs.getVersion();
    final String[] templates = HgBaseLogParser.constructFullTemplateArgument(true, version);
    return VcsFileUtil.foreachChunk(hashParameters, 2, strings -> {
        HgCommandResult logResult = getLogResult(project, root, version, limit, strings, HgChangesetUtil.makeTemplate(templates));
        if (logResult == null)
            return Collections.emptyList();
        if (!logResult.getErrorLines().isEmpty())
            throw new VcsException(logResult.getRawError());
        return createFullCommitsFromResult(project, root, logResult, version, silent);
    });
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) VcsException(com.intellij.openapi.vcs.VcsException) HgVersion(org.zmlx.hg4idea.util.HgVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class HgMergeCommand method mergeWith.

public static void mergeWith(@NotNull final HgRepository repository, @NotNull final String branchName, @NotNull final UpdatedFiles updatedFiles, @Nullable final Runnable onSuccessHandler) {
    final Project project = repository.getProject();
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgMergeCommand hgMergeCommand = new HgMergeCommand(project, repository);
    //there is no difference between branch or revision or bookmark as parameter to merge,
    hgMergeCommand.setRevision(branchName);
    // we need just a string
    new Task.Backgroundable(project, "Merging Changes...") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                HgCommandResult result = hgMergeCommand.mergeSynchronously();
                if (HgErrorUtil.isAncestorMergeError(result)) {
                    //skip and notify
                    VcsNotifier.getInstance(project).notifyMinorWarning("Merging is skipped for " + repositoryRoot.getPresentableName(), "Merging with a working directory ancestor has no effect");
                    return;
                }
                new HgConflictResolver(project, updatedFiles).resolve(repositoryRoot);
                if (!HgConflictResolver.hasConflicts(project, repositoryRoot) && onSuccessHandler != null) {
                    // for example commit changes
                    onSuccessHandler.run();
                }
            } catch (VcsException exception) {
                if (exception.isWarning()) {
                    VcsNotifier.getInstance(project).notifyWarning("Warning during merge", exception.getMessage());
                } else {
                    VcsNotifier.getInstance(project).notifyError("Exception during merge", exception.getMessage());
                }
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) HgConflictResolver(org.zmlx.hg4idea.provider.update.HgConflictResolver)

Example 33 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class SvnChangesCorrectlyRefreshedNativeTest method testModificationAndAfterRevert.

@Test
public void testModificationAndAfterRevert() throws Exception {
    final SubTree subTree = new SubTree(myWorkingCopyDir);
    checkin();
    sleep(100);
    VcsTestUtil.editFileInCommand(myProject, subTree.myS1File, "new content");
    final CharSequence text1 = LoadTextUtil.loadText(subTree.myS1File);
    Assert.assertEquals("new content", text1.toString());
    sleep(100);
    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(virtualToIoFile(subTree.myS1File));
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    clManager.ensureUpToDate(false);
    final VcsException updateException = ((ChangeListManagerImpl) clManager).getUpdateException();
    if (updateException != null) {
        updateException.printStackTrace();
    }
    Assert.assertNull(updateException == null ? null : updateException.getMessage(), updateException);
    DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] { subTree.myS1File }, clManager.getDefaultListName(), clManager);
    final Collection<Change> changes = clManager.getDefaultChangeList().getChanges();
    final RollbackWorker worker = new RollbackWorker(myProject);
    worker.doRollback(changes, false, null, null);
    final CharSequence text = LoadTextUtil.loadText(subTree.myS1File);
    Assert.assertEquals(SubTree.ourS1Contents, text.toString());
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    clManager.ensureUpToDate(false);
    DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager);
}
Also used : ChangeListManagerImpl(com.intellij.openapi.vcs.changes.ChangeListManagerImpl) VcsException(com.intellij.openapi.vcs.VcsException) Change(com.intellij.openapi.vcs.changes.Change) RollbackWorker(com.intellij.openapi.vcs.changes.ui.RollbackWorker) Test(org.junit.Test)

Example 34 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class SvnChangesCorrectlyRefreshedTest method testModificationAndAfterRevert.

@Test
public void testModificationAndAfterRevert() throws Exception {
    //ChangeListManagerImpl.DEBUG = true;
    final SubTree subTree = new SubTree(myWorkingCopyDir);
    checkin();
    sleep(100);
    VcsTestUtil.editFileInCommand(myProject, subTree.myS1File, "new content");
    final CharSequence text1 = LoadTextUtil.loadText(subTree.myS1File);
    Assert.assertEquals("new content", text1.toString());
    sleep(100);
    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(virtualToIoFile(subTree.myS1File));
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    clManager.ensureUpToDate(false);
    final VcsException updateException = ((ChangeListManagerImpl) clManager).getUpdateException();
    if (updateException != null) {
        updateException.printStackTrace();
    }
    Assert.assertNull(updateException == null ? null : updateException.getMessage(), updateException);
    DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(new VirtualFile[] { subTree.myS1File }, clManager.getDefaultListName(), clManager);
    final Collection<Change> changes = clManager.getDefaultChangeList().getChanges();
    final RollbackWorker worker = new RollbackWorker(myProject);
    worker.doRollback(changes, false, null, null);
    final CharSequence text = LoadTextUtil.loadText(subTree.myS1File);
    Assert.assertEquals(SubTree.ourS1Contents, text.toString());
    VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
    clManager.ensureUpToDate(false);
    DuringChangeListManagerUpdateTestScheme.checkFilesAreInList(VirtualFile.EMPTY_ARRAY, clManager.getDefaultListName(), clManager);
}
Also used : ChangeListManagerImpl(com.intellij.openapi.vcs.changes.ChangeListManagerImpl) VcsException(com.intellij.openapi.vcs.VcsException) Change(com.intellij.openapi.vcs.changes.Change) RollbackWorker(com.intellij.openapi.vcs.changes.ui.RollbackWorker) Test(org.junit.Test)

Example 35 with VcsException

use of com.intellij.openapi.vcs.VcsException in project intellij-community by JetBrains.

the class SvnRenameTest method testRollbackRenameDir.

// IDEADEV-9755
@Test
public void testRollbackRenameDir() throws Exception {
    final VirtualFile child = prepareDirectoriesForRename();
    renameFileInCommand(child, "newchild");
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    changeListManager.ensureUpToDate(false);
    final Change change = changeListManager.getChange(myWorkingCopyDir.findChild("newchild"));
    Assert.assertNotNull(change);
    final List<VcsException> exceptions = new ArrayList<>();
    SvnVcs.getInstance(myProject).getRollbackEnvironment().rollbackChanges(Collections.singletonList(change), exceptions, RollbackProgressListener.EMPTY);
    Assert.assertTrue(exceptions.isEmpty());
    Assert.assertFalse(new File(myWorkingCopyDir.getPath(), "newchild").exists());
    Assert.assertTrue(new File(myWorkingCopyDir.getPath(), "child").exists());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) Change(com.intellij.openapi.vcs.changes.Change) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) Test(org.junit.Test)

Aggregations

VcsException (com.intellij.openapi.vcs.VcsException)200 VirtualFile (com.intellij.openapi.vfs.VirtualFile)89 File (java.io.File)48 NotNull (org.jetbrains.annotations.NotNull)42 FilePath (com.intellij.openapi.vcs.FilePath)35 Change (com.intellij.openapi.vcs.changes.Change)33 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)26 ArrayList (java.util.ArrayList)24 Nullable (org.jetbrains.annotations.Nullable)23 IOException (java.io.IOException)20 SVNException (org.tmatesoft.svn.core.SVNException)19 Project (com.intellij.openapi.project.Project)17 Ref (com.intellij.openapi.util.Ref)16 Test (org.junit.Test)14 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)13 GitRepository (git4idea.repo.GitRepository)12 Task (com.intellij.openapi.progress.Task)11 List (java.util.List)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)10 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)10