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;
}
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;
}
}
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);
}
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);
}
}
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;
}
Aggregations