Search in sources :

Example 81 with VcsException

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

the class GitBranchOperation method collectLocalChangesConflictingWithBranch.

/**
   * TODO this is non-optimal and even incorrect, since such diff shows the difference between committed changes
   * For each of the given repositories looks to the diff between current branch and the given branch and converts it to the list of
   * local changes.
   */
@NotNull
Map<GitRepository, List<Change>> collectLocalChangesConflictingWithBranch(@NotNull Collection<GitRepository> repositories, @NotNull String currentBranch, @NotNull String otherBranch) {
    Map<GitRepository, List<Change>> changes = new HashMap<>();
    for (GitRepository repository : repositories) {
        try {
            Collection<String> diff = GitUtil.getPathsDiffBetweenRefs(myGit, repository, currentBranch, otherBranch);
            List<Change> changesInRepo = GitUtil.findLocalChangesForPaths(myProject, repository.getRoot(), diff, false);
            if (!changesInRepo.isEmpty()) {
                changes.put(repository, changesInRepo);
            }
        } catch (VcsException e) {
            // ignoring the exception: this is not fatal if we won't collect such a diff from other repositories.
            // At worst, use will get double dialog proposing the smart checkout.
            LOG.warn(String.format("Couldn't collect diff between %s and %s in %s", currentBranch, otherBranch, repository.getRoot()), e);
        }
    }
    return changes;
}
Also used : GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException) Change(com.intellij.openapi.vcs.changes.Change) ObjectUtils.chooseNotNull(com.intellij.util.ObjectUtils.chooseNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 82 with VcsException

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

the class GitBranchUtil method getCurrentBranchFromGit.

@Nullable
private static GitLocalBranch getCurrentBranchFromGit(@NotNull Project project, @NotNull VirtualFile root) {
    GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.REV_PARSE);
    handler.addParameters("--abbrev-ref", "HEAD");
    handler.setSilent(true);
    try {
        String name = handler.run();
        if (!name.equals("HEAD")) {
            return new GitLocalBranch(name);
        } else {
            return null;
        }
    } catch (VcsException e) {
        LOG.info("git rev-parse --abbrev-ref HEAD", e);
        return null;
    }
}
Also used : GitSimpleHandler(git4idea.commands.GitSimpleHandler) VcsException(com.intellij.openapi.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with VcsException

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

the class GitBranchWorker method loadCommitsToCompare.

@NotNull
private Couple<List<GitCommit>> loadCommitsToCompare(@NotNull GitRepository repository, @NotNull final String branchName) {
    final List<GitCommit> headToBranch;
    final List<GitCommit> branchToHead;
    try {
        headToBranch = GitHistoryUtils.history(myProject, repository.getRoot(), ".." + branchName);
        branchToHead = GitHistoryUtils.history(myProject, repository.getRoot(), branchName + "..");
    } catch (VcsException e) {
        // we treat it as critical and report an error
        throw new GitExecutionException("Couldn't get [git log .." + branchName + "] on repository [" + repository.getRoot() + "]", e);
    }
    return Couple.of(headToBranch, branchToHead);
}
Also used : GitCommit(git4idea.GitCommit) GitExecutionException(git4idea.GitExecutionException) VcsException(com.intellij.openapi.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with VcsException

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

the class GitMergeAction method handleResult.

private void handleResult(GitCommandResult result, Project project, GitSimpleEventDetector mergeConflictDetector, GitLocalChangesWouldBeOverwrittenDetector localChangesDetector, GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector, GitRepository repository, GitRevisionNumber currentRev, Label beforeLabel) {
    GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
    VirtualFile root = repository.getRoot();
    if (result.success() || mergeConflictDetector.hasHappened()) {
        VfsUtil.markDirtyAndRefresh(false, true, false, root);
        List<VcsException> exceptions = new ArrayList<>();
        GitMergeUtil.showUpdates(project, exceptions, root, currentRev, beforeLabel, getActionName(), ActionInfo.UPDATE);
        repositoryManager.updateRepository(root);
        showErrors(project, getActionName(), exceptions);
    } else if (localChangesDetector.wasMessageDetected()) {
        LocalChangesWouldBeOverwrittenHelper.showErrorNotification(project, repository.getRoot(), getActionName(), localChangesDetector.getRelativeFilePaths());
    } else if (untrackedFilesDetector.wasMessageDetected()) {
        GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), getActionName(), null);
    } else {
        GitUIUtil.notifyError(project, "Git " + getActionName() + " Failed", result.getErrorOutputAsJoinedString(), true, null);
        repositoryManager.updateRepository(root);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) ArrayList(java.util.ArrayList) GitRepositoryManager(git4idea.repo.GitRepositoryManager)

Example 85 with VcsException

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

the class GitUtil method sortFilesByGitRoot.

/**
   * Sort files by Git root
   *
   * @param virtualFiles files to sort
   * @param ignoreNonGit if true, non-git files are ignored
   * @return sorted files
   * @throws VcsException if non git files are passed when {@code ignoreNonGit} is false
   */
public static Map<VirtualFile, List<VirtualFile>> sortFilesByGitRoot(Collection<VirtualFile> virtualFiles, boolean ignoreNonGit) throws VcsException {
    Map<VirtualFile, List<VirtualFile>> result = new HashMap<>();
    for (VirtualFile file : virtualFiles) {
        // directory is reported only when it is a submodule => it should be treated in the context of super-root
        final VirtualFile vcsRoot = gitRootOrNull(file.isDirectory() ? file.getParent() : file);
        if (vcsRoot == null) {
            if (ignoreNonGit) {
                continue;
            } else {
                throw new VcsException("The file " + file.getPath() + " is not under Git");
            }
        }
        List<VirtualFile> files = result.get(vcsRoot);
        if (files == null) {
            files = new ArrayList<>();
            result.put(vcsRoot, files);
        }
        files.add(file);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) VcsException(com.intellij.openapi.vcs.VcsException) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) GitCommittedChangeList(git4idea.changes.GitCommittedChangeList)

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