Search in sources :

Example 1 with GitVcs

use of git4idea.GitVcs in project intellij-community by JetBrains.

the class GitResolveConflictsAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent event) {
    Project project = ObjectUtils.assertNotNull(event.getProject());
    GitVcs vcs = ObjectUtils.assertNotNull(GitVcs.getInstance(project));
    final Set<VirtualFile> conflictedFiles = new TreeSet<>(new Comparator<VirtualFile>() {

        @Override
        public int compare(@NotNull VirtualFile f1, @NotNull VirtualFile f2) {
            return f1.getPresentableUrl().compareTo(f2.getPresentableUrl());
        }
    });
    for (Change change : ChangeListManager.getInstance(project).getAllChanges()) {
        if (change.getFileStatus() != FileStatus.MERGED_WITH_CONFLICTS) {
            continue;
        }
        ContentRevision before = change.getBeforeRevision();
        ContentRevision after = change.getAfterRevision();
        if (before != null) {
            VirtualFile file = before.getFile().getVirtualFile();
            if (file != null) {
                conflictedFiles.add(file);
            }
        }
        if (after != null) {
            VirtualFile file = after.getFile().getVirtualFile();
            if (file != null) {
                conflictedFiles.add(file);
            }
        }
    }
    AbstractVcsHelper.getInstance(project).showMergeDialog(newArrayList(conflictedFiles), vcs.getMergeProvider());
    for (GitRepository repository : GitUtil.getRepositoriesForFiles(project, conflictedFiles)) {
        repository.update();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitVcs(git4idea.GitVcs) GitRepository(git4idea.repo.GitRepository) TreeSet(java.util.TreeSet) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change)

Example 2 with GitVcs

use of git4idea.GitVcs in project intellij-community by JetBrains.

the class GitAnnotationProvider method annotate.

@NotNull
private GitFileAnnotation annotate(@NotNull final FilePath repositoryFilePath, @Nullable final VcsRevisionNumber revision, @NotNull final VirtualFile file) throws VcsException {
    GitVcs vcs = GitVcs.getInstance(myProject);
    assert vcs != null;
    VcsRevisionNumber actualRevision = revision != null ? revision : vcs.getDiffProvider().getCurrentRevision(file);
    if (actualRevision != null) {
        Object annotatedData = myCache.get(repositoryFilePath, GitVcs.getKey(), actualRevision);
        if (annotatedData instanceof CachedData)
            return restoreFromCache(file, actualRevision, (CachedData) annotatedData);
    }
    GitFileAnnotation fileAnnotation = doAnnotate(repositoryFilePath, actualRevision, file);
    if (actualRevision != null) {
        myCache.put(repositoryFilePath, GitVcs.getKey(), actualRevision, cacheData(fileAnnotation));
    }
    return fileAnnotation;
}
Also used : GitVcs(git4idea.GitVcs) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitVcs

use of git4idea.GitVcs in project intellij-community by JetBrains.

the class GitRepositoryAction method actionPerformed.

public void actionPerformed(@NotNull final AnActionEvent e) {
    FileDocumentManager.getInstance().saveAllDocuments();
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    GitVcs vcs = GitVcs.getInstance(project);
    final List<VirtualFile> roots = getGitRoots(project, vcs);
    if (roots == null)
        return;
    final VirtualFile defaultRoot = getDefaultRoot(project, roots, e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
    perform(project, roots, defaultRoot);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitVcs(git4idea.GitVcs)

Example 4 with GitVcs

use of git4idea.GitVcs in project intellij-community by JetBrains.

the class BasicAction method update.

/**
   * Disable the action if the event does not apply in this context.
   *
   * @param e The update event
   */
@Override
public void update(@NotNull AnActionEvent e) {
    super.update(e);
    Presentation presentation = e.getPresentation();
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setEnabled(false);
        presentation.setVisible(false);
        return;
    }
    VirtualFile[] vFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    if (vFiles == null || vFiles.length == 0) {
        presentation.setEnabled(false);
        presentation.setVisible(true);
        return;
    }
    GitVcs vcs = GitVcs.getInstance(project);
    boolean enabled = ProjectLevelVcsManager.getInstance(project).checkAllFilesAreUnder(vcs, vFiles) && isEnabled(project, vcs, vFiles);
    // only enable action if all the targets are under the vcs and the action supports all of them
    presentation.setEnabled(enabled);
    if (ActionPlaces.isPopupPlace(e.getPlace())) {
        presentation.setVisible(enabled);
    } else {
        presentation.setVisible(true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitVcs(git4idea.GitVcs) Presentation(com.intellij.openapi.actionSystem.Presentation)

Example 5 with GitVcs

use of git4idea.GitVcs in project intellij-community by JetBrains.

the class GitCloneAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    GitVcs vcs = assertNotNull(GitVcs.getInstance(project));
    vcs.getCheckoutProvider().doCheckout(project, ProjectLevelVcsManager.getInstance(project).getCompositeCheckoutListener());
}
Also used : 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