Search in sources :

Example 6 with GitVcs

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

the class GitShowExternalLogAction method createManagerAndContent.

@NotNull
private static MyContentComponent createManagerAndContent(@NotNull Project project, @NotNull final GitVcs vcs, @NotNull final List<VirtualFile> roots, @Nullable String tabName) {
    final GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
    for (VirtualFile root : roots) {
        repositoryManager.addExternalRepository(root, GitRepositoryImpl.getInstance(root, project, true));
    }
    VcsLogManager manager = new VcsLogManager(project, ServiceManager.getService(project, VcsLogTabsProperties.class), ContainerUtil.map(roots, root -> new VcsRoot(vcs, root)));
    return new MyContentComponent(manager.createLogPanel(calcLogId(roots), tabName), roots, () -> {
        for (VirtualFile root : roots) {
            repositoryManager.removeExternalRepository(root);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) Arrays(java.util.Arrays) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitRepositoryImpl(git4idea.repo.GitRepositoryImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) VcsLogContentProvider(com.intellij.vcs.log.impl.VcsLogContentProvider) GitVcs(git4idea.GitVcs) GitUtil(git4idea.GitUtil) Task(com.intellij.openapi.progress.Task) VcsRoot(com.intellij.openapi.vcs.VcsRoot) Comparing(com.intellij.openapi.util.Comparing) GitVersion(git4idea.config.GitVersion) WindowWrapper(com.intellij.openapi.ui.WindowWrapper) Disposer(com.intellij.openapi.util.Disposer) VcsLogManager(com.intellij.vcs.log.impl.VcsLogManager) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ProgressManager(com.intellij.openapi.progress.ProgressManager) ToolWindow(com.intellij.openapi.wm.ToolWindow) StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) ChangesViewContentManager(com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager) Content(com.intellij.ui.content.Content) Disposable(com.intellij.openapi.Disposable) File(java.io.File) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) ContentFactory(com.intellij.ui.content.ContentFactory) WindowWrapperBuilder(com.intellij.openapi.ui.WindowWrapperBuilder) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ContentManager(com.intellij.ui.content.ContentManager) ObjectUtils(com.intellij.util.ObjectUtils) VcsLogTabsProperties(com.intellij.vcs.log.impl.VcsLogTabsProperties) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) FileChooser(com.intellij.openapi.fileChooser.FileChooser) javax.swing(javax.swing) VcsLogManager(com.intellij.vcs.log.impl.VcsLogManager) VcsLogTabsProperties(com.intellij.vcs.log.impl.VcsLogTabsProperties) GitRepositoryManager(git4idea.repo.GitRepositoryManager) VcsRoot(com.intellij.openapi.vcs.VcsRoot) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with GitVcs

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

the class GitMergeUtil method showUpdates.

/**
   * Show updates caused by git operation
   *
   * @param project     the context project
   * @param exceptions  the exception list
   * @param root        the git root
   * @param currentRev  the revision before update
   * @param beforeLabel the local history label before update
   * @param actionName  the action name
   * @param actionInfo  the information about the action
   */
public static void showUpdates(final Project project, final List<VcsException> exceptions, final VirtualFile root, final GitRevisionNumber currentRev, final Label beforeLabel, final String actionName, final ActionInfo actionInfo) {
    UpdatedFiles files = UpdatedFiles.create();
    MergeChangeCollector collector = new MergeChangeCollector(project, root, currentRev);
    collector.collect(files, exceptions);
    if (!exceptions.isEmpty())
        return;
    GuiUtils.invokeLaterIfNeeded(() -> {
        ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx) ProjectLevelVcsManager.getInstance(project);
        UpdateInfoTree tree = manager.showUpdateProjectInfo(files, actionName, actionInfo, false);
        tree.setBefore(beforeLabel);
        tree.setAfter(LocalHistory.getInstance().putSystemLabel(project, "After update"));
    }, ModalityState.defaultModalityState());
    Collection<String> unmergedNames = files.getGroupById(FileGroup.MERGED_WITH_CONFLICT_ID).getFiles();
    if (!unmergedNames.isEmpty()) {
        List<VirtualFile> unmerged = mapNotNull(unmergedNames, name -> LocalFileSystem.getInstance().findFileByPath(name));
        GuiUtils.invokeLaterIfNeeded(() -> {
            GitVcs vcs = GitVcs.getInstance(project);
            if (vcs != null) {
                AbstractVcsHelper.getInstance(project).showMergeDialog(unmerged, vcs.getMergeProvider());
            }
        }, ModalityState.defaultModalityState());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitVcs(git4idea.GitVcs) ProjectLevelVcsManagerEx(com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles) UpdateInfoTree(com.intellij.openapi.vcs.update.UpdateInfoTree)

Example 8 with GitVcs

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

the class GitChangeProvider method getChanges.

@Override
public void getChanges(@NotNull VcsDirtyScope dirtyScope, @NotNull final ChangelistBuilder builder, @NotNull final ProgressIndicator progress, @NotNull final ChangeListManagerGate addGate) throws VcsException {
    final GitVcs vcs = GitVcs.getInstance(myProject);
    if (vcs == null) {
        // already disposed or not yet initialized => ignoring
        return;
    }
    if (LOG.isDebugEnabled())
        LOG.debug("initial dirty scope: " + dirtyScope);
    appendNestedVcsRootsToDirt(dirtyScope, vcs, myVcsManager);
    if (LOG.isDebugEnabled())
        LOG.debug("after adding nested vcs roots to dirt: " + dirtyScope);
    final Collection<VirtualFile> affected = dirtyScope.getAffectedContentRoots();
    Collection<VirtualFile> roots = GitUtil.gitRootsForPaths(affected);
    try {
        final MyNonChangedHolder holder = new MyNonChangedHolder(myProject, dirtyScope.getDirtyFilesNoExpand(), addGate, myFileDocumentManager, myVcsManager);
        for (VirtualFile root : roots) {
            LOG.debug("checking root: " + root.getPath());
            GitChangesCollector collector = isNewGitChangeProviderAvailable() ? GitNewChangesCollector.collect(myProject, myGit, myChangeListManager, myVcsManager, vcs, dirtyScope, root) : GitOldChangesCollector.collect(myProject, myChangeListManager, myVcsManager, vcs, dirtyScope, root);
            final Collection<Change> changes = collector.getChanges();
            holder.changed(changes);
            for (Change file : changes) {
                LOG.debug("process change: " + ChangesUtil.getFilePath(file).getPath());
                builder.processChange(file, GitVcs.getKey());
            }
            for (VirtualFile f : collector.getUnversionedFiles()) {
                builder.processUnversionedFile(f);
                holder.unversioned(f);
            }
            holder.feedBuilder(builder);
        }
    } catch (VcsException e) {
        LOG.info(e);
        // most probably the error happened because git is not configured
        vcs.getExecutableValidator().showNotificationOrThrow(e);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitVcs(git4idea.GitVcs)

Example 9 with GitVcs

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

the class GitChangeProvider method isNewGitChangeProviderAvailable.

private boolean isNewGitChangeProviderAvailable() {
    GitVcs vcs = GitVcs.getInstance(myProject);
    if (vcs == null) {
        return false;
    }
    final GitVersion version = vcs.getVersion();
    return GitVersionSpecialty.KNOWS_STATUS_PORCELAIN.existsIn(version);
}
Also used : GitVcs(git4idea.GitVcs) GitVersion(git4idea.config.GitVersion)

Example 10 with GitVcs

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

the class GitFetcher method displayFetchResult.

public static void displayFetchResult(@NotNull Project project, @NotNull GitFetchResult result, @Nullable String errorNotificationTitle, @NotNull Collection<? extends Exception> errors) {
    if (result.isSuccess()) {
        VcsNotifier.getInstance(project).notifySuccess("Fetched successfully" + result.getAdditionalInfo());
    } else if (result.isCancelled()) {
        VcsNotifier.getInstance(project).notifyMinorWarning("", "Fetch cancelled by user" + result.getAdditionalInfo());
    } else if (result.isNotAuthorized()) {
        String title;
        String description;
        if (errorNotificationTitle != null) {
            title = errorNotificationTitle;
            description = "Fetch failed: couldn't authorize";
        } else {
            title = "Fetch failed";
            description = "Couldn't authorize";
        }
        description += result.getAdditionalInfo();
        GitUIUtil.notifyMessage(project, title, description, true, null);
    } else {
        GitVcs instance = GitVcs.getInstance(project);
        if (instance != null && instance.getExecutableValidator().isExecutableValid()) {
            GitUIUtil.notifyMessage(project, "Fetch failed", result.getAdditionalInfo(), true, errors);
        }
    }
}
Also used : 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