use of git4idea.GitVcs in project intellij-community by JetBrains.
the class GitAnnotationProvider method loadFileHistory.
@Nullable
private List<VcsFileRevision> loadFileHistory(@NotNull FilePath filePath) throws VcsException {
GitVcs vcs = GitVcs.getInstance(myProject);
if (vcs == null)
return null;
GitHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
VcsAbstractHistorySession cachedSession = myCache.getFull(filePath, vcs.getKeyInstanceMethod(), historyProvider);
if (cachedSession != null && !ContainerUtil.isEmpty(cachedSession.getRevisionList())) {
return cachedSession.getRevisionList();
} else {
VcsAbstractHistorySession session = historyProvider.createSessionFor(filePath);
if (session == null)
return null;
myCache.put(filePath, null, vcs.getKeyInstanceMethod(), session, historyProvider, true);
return session.getRevisionList();
}
}
use of git4idea.GitVcs in project intellij-community by JetBrains.
the class BasicAction method collectAffectedFiles.
/**
* given a list of action-target files, returns ALL the files that should be
* subject to the action Does not keep directories, but recursively adds
* directory contents
*
* @param project the project subject of the action
* @param files the root selection
* @return the complete set of files this action should apply to
*/
@NotNull
protected VirtualFile[] collectAffectedFiles(@NotNull Project project, @NotNull VirtualFile[] files) {
List<VirtualFile> affectedFiles = new ArrayList<>(files.length);
ProjectLevelVcsManager projectLevelVcsManager = ProjectLevelVcsManager.getInstance(project);
for (VirtualFile file : files) {
if (!file.isDirectory() && projectLevelVcsManager.getVcsFor(file) instanceof GitVcs) {
affectedFiles.add(file);
} else if (file.isDirectory() && isRecursive()) {
addChildren(project, affectedFiles, file);
}
}
return VfsUtilCore.toVirtualFileArray(affectedFiles);
}
use of git4idea.GitVcs in project intellij-community by JetBrains.
the class BasicAction method actionPerformed.
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
final Project project = event.getData(CommonDataKeys.PROJECT);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
}
});
final VirtualFile[] vFiles = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
assert vFiles != null : "The action is only available when files are selected";
assert project != null;
final GitVcs vcs = GitVcs.getInstance(project);
if (!ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(vcs, vFiles)) {
return;
}
final String actionName = getActionName();
final VirtualFile[] affectedFiles = collectAffectedFiles(project, vFiles);
final List<VcsException> exceptions = new ArrayList<>();
final boolean background = perform(project, vcs, exceptions, affectedFiles);
if (!background) {
GitVcs.runInBackground(new Task.Backgroundable(project, getActionName()) {
public void run(@NotNull ProgressIndicator indicator) {
VfsUtil.markDirtyAndRefresh(false, true, false, affectedFiles);
VcsFileUtil.markFilesDirty(project, Arrays.asList(affectedFiles));
UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() {
GitUIUtil.showOperationErrors(project, exceptions, actionName);
}
});
}
});
}
}
use of git4idea.GitVcs in project intellij-community by JetBrains.
the class GitMerge method displayDialog.
@Nullable
@Override
protected DialogState displayDialog(@NotNull Project project, @NotNull List<VirtualFile> gitRoots, @NotNull VirtualFile defaultRoot) {
GitVcs vcs = GitVcs.getInstance(project);
if (vcs == null) {
return null;
}
final GitMergeDialog dialog = new GitMergeDialog(project, gitRoots, defaultRoot);
try {
dialog.updateBranches();
} catch (VcsException e) {
if (vcs.getExecutableValidator().checkExecutableAndShowMessageIfNeeded(null)) {
vcs.showErrors(Collections.singletonList(e), GitBundle.getString("merge.retrieving.branches"));
}
return null;
}
if (!dialog.showAndGet()) {
return null;
}
return new DialogState(dialog.getSelectedRoot(), GitBundle.message("merging.title", dialog.getSelectedRoot().getPath()), new Computable<GitLineHandler>() {
@Override
public GitLineHandler compute() {
return dialog.handler();
}
});
}
use of git4idea.GitVcs in project intellij-community by JetBrains.
the class GitRepositoryAction method isEnabled.
protected boolean isEnabled(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return false;
}
GitVcs vcs = GitVcs.getInstance(project);
final VirtualFile[] roots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
if (roots == null || roots.length == 0) {
return false;
}
return true;
}
Aggregations