Search in sources :

Example 51 with GitRepository

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

the class GitRebaseUtils method isRebaseAllowed.

private static boolean isRebaseAllowed(@NotNull Project project, @NotNull Collection<GitRepository> repositories) {
    // TODO links to 'rebase', 'resolve conflicts', etc.
    for (GitRepository repository : repositories) {
        Repository.State state = repository.getState();
        String in = GitUtil.mention(repository);
        String message = null;
        switch(state) {
            case NORMAL:
                if (repository.isFresh()) {
                    message = "Repository" + in + " is empty.";
                }
                break;
            case MERGING:
                message = "There is an unfinished merge process" + in + ".<br/>You should complete the merge before starting a rebase";
                break;
            case REBASING:
                message = "There is an unfinished rebase process" + in + ".<br/>You should complete it before starting another rebase";
                break;
            case GRAFTING:
                message = "There is an unfinished cherry-pick process" + in + ".<br/>You should finish it before starting a rebase.";
                break;
            case DETACHED:
                message = "You are in the detached HEAD state" + in + ".<br/>Rebase is not possible.";
                break;
            default:
                LOG.error("Unknown state [" + state.name() + "]");
                message = "Rebase is not possible" + in;
        }
        if (message != null) {
            VcsNotifier.getInstance(project).notifyError("Rebase not Allowed", message);
            return false;
        }
    }
    return true;
}
Also used : GitRepository(git4idea.repo.GitRepository) Repository(com.intellij.dvcs.repo.Repository) GitRepository(git4idea.repo.GitRepository)

Example 52 with GitRepository

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

the class GitCompareBranchesLogPanel method createNorthPanel.

private JComponent createNorthPanel() {
    final JComboBox repoSelector = new JComboBox(ArrayUtil.toObjectArray(myCompareInfo.getRepositories(), GitRepository.class));
    repoSelector.setRenderer(new GitRepositoryComboboxListCellRenderer(repoSelector));
    repoSelector.setSelectedItem(myInitialRepo);
    repoSelector.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            GitRepository selectedRepo = (GitRepository) repoSelector.getSelectedItem();
            myHeadToBranchListPanel.setCommits(getHeadToBranchCommits(selectedRepo));
            myBranchToHeadListPanel.setCommits(getBranchToHeadCommits(selectedRepo));
        }
    });
    JPanel repoSelectorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    JBLabel label = new JBLabel("Repository: ");
    label.setLabelFor(repoSelectorPanel);
    label.setDisplayedMnemonic(KeyEvent.VK_R);
    repoSelectorPanel.add(label);
    repoSelectorPanel.add(repoSelector);
    if (myCompareInfo.getRepositories().size() < 2) {
        repoSelectorPanel.setVisible(false);
    }
    return repoSelectorPanel;
}
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 53 with GitRepository

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

the class GitLogBranchOperationsActionGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(AnActionEvent e) {
    if (e == null)
        return AnAction.EMPTY_ARRAY;
    Project project = e.getProject();
    VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
    VcsLogUi logUI = e.getData(VcsLogDataKeys.VCS_LOG_UI);
    List<VcsRef> branches = e.getData(VcsLogDataKeys.VCS_LOG_BRANCHES);
    if (project == null || log == null || logUI == null || branches == null) {
        return AnAction.EMPTY_ARRAY;
    }
    List<CommitId> commits = log.getSelectedCommits();
    if (commits.size() != 1)
        return AnAction.EMPTY_ARRAY;
    CommitId commit = commits.get(0);
    GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
    final GitRepository root = repositoryManager.getRepositoryForRoot(commit.getRoot());
    if (root == null)
        return AnAction.EMPTY_ARRAY;
    List<VcsRef> vcsRefs = ContainerUtil.filter(branches, new Condition<VcsRef>() {

        @Override
        public boolean value(VcsRef ref) {
            if (ref.getType() == GitRefManager.LOCAL_BRANCH) {
                return !ref.getName().equals(root.getCurrentBranchName());
            }
            if (ref.getType() == GitRefManager.REMOTE_BRANCH)
                return true;
            return false;
        }
    });
    VcsLogProvider provider = logUI.getDataPack().getLogProviders().get(root.getRoot());
    if (provider != null) {
        VcsLogRefManager refManager = provider.getReferenceManager();
        Comparator<VcsRef> comparator = refManager.getLabelsOrderComparator();
        ContainerUtil.sort(vcsRefs, comparator);
    }
    if (vcsRefs.isEmpty())
        return AnAction.EMPTY_ARRAY;
    GitVcsSettings settings = GitVcsSettings.getInstance(project);
    boolean showBranchesPopup = vcsRefs.size() > MAX_BRANCH_GROUPS;
    List<AnAction> branchActionGroups = new ArrayList<>();
    for (VcsRef ref : vcsRefs) {
        branchActionGroups.add(createBranchGroup(project, ref, root, repositoryManager, settings, showBranchesPopup));
    }
    DefaultActionGroup branchesGroup = new DefaultActionGroup("Branches", branchActionGroups);
    branchesGroup.setPopup(showBranchesPopup);
    return new AnAction[] { branchesGroup };
}
Also used : GitVcsSettings(git4idea.config.GitVcsSettings) ArrayList(java.util.ArrayList) GitRepositoryManager(git4idea.repo.GitRepositoryManager) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with GitRepository

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

the class GitFetcher method fetch.

@NotNull
public GitFetchResult fetch(@NotNull VirtualFile root, @NotNull String remoteName, @Nullable String branch) {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null) {
        return logError("Repository can't be null for " + root, myRepositoryManager.toString());
    }
    GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
    if (remote == null) {
        return logError("Couldn't find remote with the name " + remoteName, null);
    }
    return fetchRemote(repository, remote, branch);
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 55 with GitRepository

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

the class GitFetcher method fetchRootsAndNotify.

/**
   * Fetches all specified roots.
   * Once a root has failed, stops and displays the notification.
   * If needed, displays the successful notification at the end.
   * @param roots                   roots to fetch.
   * @param errorNotificationTitle  if specified, this notification title will be used instead of the standard "Fetch failed".
   *                                Use this when fetch is a part of a compound process.
   * @param notifySuccess           if set to {@code true} successful notification will be displayed.
   * @return true if all fetches were successful, false if at least one fetch failed.
   */
public boolean fetchRootsAndNotify(@NotNull Collection<GitRepository> roots, @Nullable String errorNotificationTitle, boolean notifySuccess) {
    MultiRootMessage additionalInfo = new MultiRootMessage(myProject, GitUtil.getRootsFromRepositories(roots), true);
    for (GitRepository repository : roots) {
        LOG.info("fetching " + repository);
        GitFetchResult result = fetch(repository);
        String ai = result.getAdditionalInfo();
        if (!StringUtil.isEmptyOrSpaces(ai)) {
            additionalInfo.append(repository.getRoot(), ai);
        }
        if (!result.isSuccess()) {
            Collection<Exception> errors = new ArrayList<>(getErrors());
            errors.addAll(result.getErrors());
            displayFetchResult(myProject, result, errorNotificationTitle, errors);
            return false;
        }
    }
    if (notifySuccess) {
        VcsNotifier.getInstance(myProject).notifySuccess("Fetched successfully");
    }
    if (!additionalInfo.asString().isEmpty()) {
        VcsNotifier.getInstance(myProject).notifyMinorInfo("Fetch details", additionalInfo.asString());
    }
    return true;
}
Also used : GitRepository(git4idea.repo.GitRepository) ArrayList(java.util.ArrayList) MultiRootMessage(com.intellij.dvcs.MultiRootMessage)

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