Search in sources :

Example 21 with GitRemote

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

the class GitPullDialog method setupGetBranches.

private void setupGetBranches() {
    myGetBranchesButton.setIcon(AllIcons.Actions.Refresh);
    myGetBranchesButton.setEnabled(myRemote.getItemCount() >= 1);
    myGetBranchesButton.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            GitRemote selectedItem = (GitRemote) myRemote.getSelectedItem();
            Collection<String> remoteBranches = selectedItem != null ? getRemoteBranches(selectedItem) : null;
            if (remoteBranches != null) {
                myBranchChooser.removeAllElements();
                for (String branch : remoteBranches) {
                    myBranchChooser.addElement(branch, false);
                }
            }
        }
    });
}
Also used : GitRemote(git4idea.repo.GitRemote) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Collection(java.util.Collection)

Example 22 with GitRemote

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

the class GithubCreatePullRequestWorker method create.

@Nullable
public static GithubCreatePullRequestWorker create(@NotNull final Project project, @Nullable final VirtualFile file) {
    return GithubUtil.computeValueInModal(project, "Loading data...", indicator -> {
        Git git = ServiceManager.getService(Git.class);
        GitRepository gitRepository = GithubUtil.getGitRepository(project, file);
        if (gitRepository == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find git repository");
            return null;
        }
        gitRepository.update();
        Pair<GitRemote, String> remote = GithubUtil.findGithubRemote(gitRepository);
        if (remote == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't find GitHub remote");
            return null;
        }
        String remoteName = remote.getFirst().getName();
        String remoteUrl = remote.getSecond();
        GithubFullPath path = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(remoteUrl);
        if (path == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "Can't process remote: " + remoteUrl);
            return null;
        }
        GitLocalBranch currentBranch = gitRepository.getCurrentBranch();
        if (currentBranch == null) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, "No current branch");
            return null;
        }
        GithubAuthDataHolder authHolder;
        try {
            authHolder = GithubUtil.getValidAuthDataHolderFromConfig(project, AuthLevel.LOGGED, indicator);
        } catch (IOException e) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
            return null;
        }
        GithubCreatePullRequestWorker worker = new GithubCreatePullRequestWorker(project, git, gitRepository, authHolder, path, remoteName, remoteUrl, currentBranch.getName());
        try {
            worker.initForks(indicator);
        } catch (IOException e) {
            GithubNotifications.showError(project, CANNOT_CREATE_PULL_REQUEST, e);
            return null;
        }
        return worker;
    });
}
Also used : GitRemote(git4idea.repo.GitRemote) GitRepository(git4idea.repo.GitRepository) GitLocalBranch(git4idea.GitLocalBranch) Git(git4idea.commands.Git) IOException(java.io.IOException) GithubFullPath(org.jetbrains.plugins.github.api.GithubFullPath) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitRemote (git4idea.repo.GitRemote)22 NotNull (org.jetbrains.annotations.NotNull)8 GitRepository (git4idea.repo.GitRepository)7 Nullable (org.jetbrains.annotations.Nullable)7 GitRemoteBranch (git4idea.GitRemoteBranch)3 GitBranchTrackInfo (git4idea.repo.GitBranchTrackInfo)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 SimpleRefGroup (com.intellij.vcs.log.impl.SimpleRefGroup)2 GitLocalBranch (git4idea.GitLocalBranch)2 GitStandardRemoteBranch (git4idea.GitStandardRemoteBranch)2 Computable (com.intellij.openapi.util.Computable)1 VcsException (com.intellij.openapi.vcs.VcsException)1 MultiMap (com.intellij.util.containers.MultiMap)1 SingletonRefGroup (com.intellij.vcs.log.impl.SingletonRefGroup)1 Git (git4idea.commands.Git)1 GitCommandResult (git4idea.commands.GitCommandResult)1 GitCompoundResult (git4idea.commands.GitCompoundResult)1 GitLineHandler (git4idea.commands.GitLineHandler)1 GitPullDialog (git4idea.merge.GitPullDialog)1 GitRepositoryManager (git4idea.repo.GitRepositoryManager)1