Search in sources :

Example 1 with VcsException

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

the class HgRegularUpdater method update.

public boolean update(final UpdatedFiles updatedFiles, ProgressIndicator indicator, List<VcsException> warnings) throws VcsException {
    indicator.setText(HgVcsMessages.message("hg4idea.progress.updating", repoRoot.getPath()));
    String defaultPath = HgUtil.getRepositoryDefaultPath(project, repoRoot);
    if (StringUtil.isEmptyOrSpaces(defaultPath)) {
        throw new VcsException(HgVcsMessages.message("hg4idea.warning.no-default-update-path", repoRoot.getPath()));
    }
    List<HgRevisionNumber> branchHeadsBeforePull = new HgHeadsCommand(project, repoRoot).executeInCurrentThread();
    if (branchHeadsBeforePull.size() > 1) {
        reportWarning(warnings, HgVcsMessages.message("hg4idea.update.warning.multipleHeadsBeforeUpdate", repoRoot.getPath()));
    }
    if (updateConfiguration.shouldPull()) {
        HgCommandExitCode pullResult = pull(repoRoot, indicator);
        if (pullResult == HgCommandExitCode.ERROR) {
            return false;
        }
    }
    List<HgRevisionNumber> parentsBeforeUpdate = new HgWorkingCopyRevisionsCommand(project).parents(repoRoot);
    if (parentsBeforeUpdate.size() > 1) {
        throw new VcsException(HgVcsMessages.message("hg4idea.update.error.uncommittedMerge", repoRoot.getPath()));
    }
    indicator.setText2(HgVcsMessages.message("hg4idea.progress.countingHeads"));
    List<HgRevisionNumber> branchHeadsAfterPull = new HgHeadsCommand(project, repoRoot).executeInCurrentThread();
    List<HgRevisionNumber> pulledBranchHeads = determinePulledBranchHeads(branchHeadsBeforePull, branchHeadsAfterPull);
    List<HgRevisionNumber> remainingOriginalBranchHeads = determingRemainingOriginalBranchHeads(branchHeadsBeforePull, branchHeadsAfterPull);
    HgUpdateType updateType = updateConfiguration.getUpdateType();
    if (branchHeadsAfterPull.size() > 1 && updateType != ONLY_UPDATE) {
        // merge strategy
        if (updateType == MERGE) {
            abortOnLocalChanges();
            abortOnMultiplePulledHeads(pulledBranchHeads);
            abortOnMultipleLocalHeads(remainingOriginalBranchHeads);
            HgCommandResult mergeResult = doMerge(indicator);
            if (updateConfiguration.shouldCommitAfterMerge()) {
                commitOrWarnAboutConflicts(warnings, mergeResult);
            }
        } else //rebase strategy
        {
            //resolve conflicts processed during rebase
            processRebase(indicator, updatedFiles);
            return true;
        }
    } else //if pull complete successfully and there are only one head, we need just update working directory to the head
    {
        //in case of multiple heads the update will report the appropriate error
        update(repoRoot, indicator, updatedFiles, warnings);
    }
    //any kind of update could have resulted in merges and merge conflicts, so run the resolver
    resolvePossibleConflicts(updatedFiles);
    return true;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) VcsException(com.intellij.openapi.vcs.VcsException)

Example 2 with VcsException

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

the class HgUpdateEnvironment method updateDirectories.

@NotNull
public UpdateSession updateDirectories(@NotNull FilePath[] contentRoots, UpdatedFiles updatedFiles, ProgressIndicator indicator, @NotNull Ref<SequentialUpdatesContext> context) {
    List<VcsException> exceptions = new LinkedList<>();
    boolean result = true;
    for (FilePath contentRoot : contentRoots) {
        if (indicator != null) {
            indicator.checkCanceled();
            indicator.startNonCancelableSection();
        }
        VirtualFile repository = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(contentRoot);
        if (repository == null) {
            continue;
        }
        try {
            HgUpdater updater = new HgRegularUpdater(project, repository, updateConfiguration);
            result &= updater.update(updatedFiles, indicator, exceptions);
        } catch (VcsException e) {
            //TODO include module name where exception occurred
            exceptions.add(e);
        }
        if (indicator != null) {
            indicator.finishNonCancelableSection();
        }
    }
    return new UpdateSessionAdapter(exceptions, !result);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with VcsException

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

the class SvnCheckinEnvironment method doCommitOneRepo.

private void doCommitOneRepo(@NotNull Collection<FilePath> committables, String comment, List<VcsException> exception, final Set<String> feedback, @NotNull WorkingCopyFormat format) throws VcsException {
    if (committables.isEmpty()) {
        return;
    }
    CommitInfo[] results = mySvnVcs.getFactory(format).createCheckinClient().commit(ChangesUtil.filePathsToFiles(committables), comment);
    final StringBuilder committedRevisions = new StringBuilder();
    for (CommitInfo result : results) {
        if (result.getErrorMessage() != null) {
            exception.add(new VcsException(result.getErrorMessage().getFullMessage()));
        } else if (result != CommitInfo.EMPTY && result.getRevision() > 0) {
            if (committedRevisions.length() > 0) {
                committedRevisions.append(", ");
            }
            committedRevisions.append(result.getRevision());
        }
    }
    if (committedRevisions.length() > 0) {
        reportCommittedRevisions(feedback, committedRevisions.toString());
    }
}
Also used : VcsException(com.intellij.openapi.vcs.VcsException)

Example 4 with VcsException

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

the class SvnAnnotationProvider method annotate.

public FileAnnotation annotate(final VirtualFile file) throws VcsException {
    final SvnDiffProvider provider = (SvnDiffProvider) myVcs.getDiffProvider();
    final SVNRevision currentRevision = ((SvnRevisionNumber) provider.getCurrentRevision(file)).getRevision();
    final VcsRevisionDescription lastChangedRevision = provider.getCurrentRevisionDescription(file);
    if (lastChangedRevision == null) {
        throw new VcsException("Can not get current revision for file " + file.getPath());
    }
    final SVNRevision svnRevision = ((SvnRevisionNumber) lastChangedRevision.getRevisionNumber()).getRevision();
    if (!svnRevision.isValid()) {
        throw new VcsException("Can not get last changed revision for file: " + file.getPath() + "\nPlease run svn info for this file and file an issue.");
    }
    return annotate(file, new SvnFileRevision(myVcs, currentRevision, currentRevision, null, null, null, null, null), lastChangedRevision.getRevisionNumber(), true);
}
Also used : SvnFileRevision(org.jetbrains.idea.svn.history.SvnFileRevision) VcsException(com.intellij.openapi.vcs.VcsException) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision)

Example 5 with VcsException

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

the class SvnAnnotationProvider method annotateNonExisting.

private SvnRemoteFileAnnotation annotateNonExisting(Pair<SvnChangeList, FilePath> pair, VcsFileRevision revision, Info info, Charset charset, final VirtualFile current) throws VcsException, SVNException, IOException {
    final File wasFile = pair.getSecond().getIOFile();
    final File root = getCommonAncestor(wasFile, info.getFile());
    if (root == null) {
        throw new VcsException("Can not find relative path for " + wasFile.getPath() + "@" + revision.getRevisionNumber().asString());
    }
    final String relativePath = FileUtil.getRelativePath(root.getPath(), wasFile.getPath(), File.separatorChar);
    if (relativePath == null) {
        throw new VcsException("Can not find relative path for " + wasFile.getPath() + "@" + revision.getRevisionNumber().asString());
    }
    Info wcRootInfo = myVcs.getInfo(root);
    if (wcRootInfo == null || wcRootInfo.getURL() == null) {
        throw new VcsException("Can not find relative path for " + wasFile.getPath() + "@" + revision.getRevisionNumber().asString());
    }
    SVNURL wasUrl = wcRootInfo.getURL();
    final String[] strings = relativePath.replace('\\', '/').split("/");
    for (String string : strings) {
        wasUrl = wasUrl.appendPath(string, true);
    }
    final SVNRevision svnRevision = ((SvnRevisionNumber) revision.getRevisionNumber()).getRevision();
    byte[] data = SvnUtil.getFileContents(myVcs, SvnTarget.fromURL(wasUrl), svnRevision, svnRevision);
    final String contents = LoadTextUtil.getTextByBinaryPresentation(data, charset == null ? CharsetToolkit.UTF8_CHARSET : charset).toString();
    final SvnRemoteFileAnnotation result = new SvnRemoteFileAnnotation(myVcs, contents, revision.getRevisionNumber(), current);
    final AnnotationConsumer annotateHandler = createAnnotationHandler(ProgressManager.getInstance().getProgressIndicator(), result);
    boolean calculateMergeinfo = myVcs.getSvnConfiguration().isShowMergeSourcesInAnnotate() && SvnUtil.checkRepositoryVersion15(myVcs, wasUrl.toString());
    AnnotateClient client = myVcs.getFactory().createAnnotateClient();
    client.annotate(SvnTarget.fromURL(wasUrl, svnRevision), SVNRevision.create(1), svnRevision, calculateMergeinfo, getLogClientOptions(myVcs), annotateHandler);
    return result;
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) Info(org.jetbrains.idea.svn.info.Info) VcsException(com.intellij.openapi.vcs.VcsException) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

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