Search in sources :

Example 1 with GitRepository

use of git4idea.repo.GitRepository 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 GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class DeepComparator method getRepositories.

@NotNull
private Map<GitRepository, GitBranch> getRepositories(@NotNull Map<VirtualFile, VcsLogProvider> providers, @NotNull String branchToCompare) {
    Map<GitRepository, GitBranch> repos = ContainerUtil.newHashMap();
    for (VirtualFile root : providers.keySet()) {
        GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
        if (repository == null || repository.getCurrentBranch() == null || repository.getBranches().findBranchByName(branchToCompare) == null) {
            continue;
        }
        repos.put(repository, repository.getCurrentBranch());
    }
    return repos;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitRepository(git4idea.repo.GitRepository) GitBranch(git4idea.GitBranch) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchIsNotFullyMergedDialog method createNorthPanel.

@Override
protected JComponent createNorthPanel() {
    JBLabel descriptionLabel = new JBLabel(makeDescription(myInitialRepository));
    JComboBox repositorySelector = new JComboBox(ArrayUtil.toObjectArray(myRepositories, GitRepository.class));
    repositorySelector.setRenderer(new GitRepositoryComboboxListCellRenderer(repositorySelector));
    repositorySelector.setSelectedItem(myInitialRepository);
    repositorySelector.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            GitRepository selectedRepo = (GitRepository) repositorySelector.getSelectedItem();
            descriptionLabel.setText(makeDescription(selectedRepo));
            myCommitListWithDiffPanel.setCommits(myCommits.get(selectedRepo));
        }
    });
    JPanel repoSelectorPanel = new JPanel(new BorderLayout());
    JBLabel label = new JBLabel("Repository: ");
    label.setLabelFor(repoSelectorPanel);
    repoSelectorPanel.add(label, BorderLayout.WEST);
    repoSelectorPanel.add(repositorySelector);
    if (myRepositories.size() < 2) {
        repoSelectorPanel.setVisible(false);
    }
    JPanel northPanel = new JPanel(new BorderLayout());
    northPanel.add(descriptionLabel);
    northPanel.add(repoSelectorPanel, BorderLayout.SOUTH);
    return northPanel;
}
Also used : GitRepository(git4idea.repo.GitRepository) GitRepositoryComboboxListCellRenderer(git4idea.ui.GitRepositoryComboboxListCellRenderer) ActionListener(java.awt.event.ActionListener) JBLabel(com.intellij.ui.components.JBLabel) ActionEvent(java.awt.event.ActionEvent)

Example 4 with GitRepository

use of git4idea.repo.GitRepository 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;
}
Also used : GitRepository(git4idea.repo.GitRepository) VcsException(com.intellij.openapi.vcs.VcsException) Change(com.intellij.openapi.vcs.changes.Change) ObjectUtils.chooseNotNull(com.intellij.util.ObjectUtils.chooseNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GitRepository

use of git4idea.repo.GitRepository in project intellij-community by JetBrains.

the class GitBranchOperation method markSkip.

/**
   * Marks repositories as successful, i.e. they won't be handled again.
   */
protected void markSkip(GitRepository... repositories) {
    for (GitRepository repository : repositories) {
        mySkippedRepositories.add(repository);
        myRemainingRepositories.remove(repository);
    }
}
Also used : GitRepository(git4idea.repo.GitRepository)

Aggregations

GitRepository (git4idea.repo.GitRepository)123 VirtualFile (com.intellij.openapi.vfs.VirtualFile)46 NotNull (org.jetbrains.annotations.NotNull)33 Nullable (org.jetbrains.annotations.Nullable)19 Project (com.intellij.openapi.project.Project)18 GitCommandResult (git4idea.commands.GitCommandResult)14 GitRepositoryManager (git4idea.repo.GitRepositoryManager)12 VcsException (com.intellij.openapi.vcs.VcsException)11 AccessToken (com.intellij.openapi.application.AccessToken)9 File (java.io.File)8 Map (java.util.Map)8 GitRemote (git4idea.repo.GitRemote)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Change (com.intellij.openapi.vcs.changes.Change)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 Task (com.intellij.openapi.progress.Task)5 ArrayList (java.util.ArrayList)5 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)4 MultiMap (com.intellij.util.containers.MultiMap)4 GitBranch (git4idea.GitBranch)4