Search in sources :

Example 11 with GitVcs

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();
    }
}
Also used : GitVcs(git4idea.GitVcs) GitHistoryProvider(git4idea.history.GitHistoryProvider) VcsAbstractHistorySession(com.intellij.openapi.vcs.history.VcsAbstractHistorySession) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with GitVcs

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitVcs(git4idea.GitVcs) ArrayList(java.util.ArrayList) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with GitVcs

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);
                    }
                });
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) GitVcs(git4idea.GitVcs) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException)

Example 14 with GitVcs

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();
        }
    });
}
Also used : GitVcs(git4idea.GitVcs) GitLineHandler(git4idea.commands.GitLineHandler) GitMergeDialog(git4idea.merge.GitMergeDialog) VcsException(com.intellij.openapi.vcs.VcsException) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with GitVcs

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitVcs(git4idea.GitVcs)

Aggregations

GitVcs (git4idea.GitVcs)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Project (com.intellij.openapi.project.Project)8 NotNull (org.jetbrains.annotations.NotNull)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)2 VcsException (com.intellij.openapi.vcs.VcsException)2 ChangesViewContentManager (com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager)2 ToolWindow (com.intellij.openapi.wm.ToolWindow)2 Content (com.intellij.ui.content.Content)2 ContentManager (com.intellij.ui.content.ContentManager)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 Disposable (com.intellij.openapi.Disposable)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 FileChooser (com.intellij.openapi.fileChooser.FileChooser)1