Search in sources :

Example 1 with GitCloneDialog

use of git4idea.checkout.GitCloneDialog in project intellij-community by JetBrains.

the class GithubCheckoutProvider method doCheckout.

@Override
public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
    if (!GithubUtil.testGitExecutable(project)) {
        return;
    }
    BasicAction.saveAll();
    List<GithubRepo> availableRepos;
    try {
        availableRepos = GithubUtil.computeValueInModalIO(project, "Access to GitHub", indicator -> GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator, connection -> GithubApiUtil.getAvailableRepos(connection)));
    } catch (IOException e) {
        GithubNotifications.showError(project, "Couldn't get the list of GitHub repositories", e);
        return;
    }
    Collections.sort(availableRepos, (r1, r2) -> {
        final int comparedOwners = r1.getUserName().compareTo(r2.getUserName());
        return comparedOwners != 0 ? comparedOwners : r1.getName().compareTo(r2.getName());
    });
    final GitCloneDialog dialog = new GitCloneDialog(project);
    // Add predefined repositories to history
    dialog.prependToHistory("-----------------------------------------------");
    for (int i = availableRepos.size() - 1; i >= 0; i--) {
        dialog.prependToHistory(GithubUrlUtil.getCloneUrl(availableRepos.get(i).getFullPath()));
    }
    if (!dialog.showAndGet()) {
        return;
    }
    dialog.rememberSettings();
    final VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
    if (destinationParent == null) {
        return;
    }
    final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
    final String directoryName = dialog.getDirectoryName();
    final String parentDirectory = dialog.getParentDirectory();
    Git git = ServiceManager.getService(Git.class);
    GitCheckoutProvider.clone(project, git, listener, destinationParent, sourceRepositoryURL, directoryName, parentDirectory);
}
Also used : Git(git4idea.commands.Git) GitCheckoutProvider(git4idea.checkout.GitCheckoutProvider) GithubUrlUtil(org.jetbrains.plugins.github.util.GithubUrlUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BasicAction(git4idea.actions.BasicAction) File(java.io.File) GithubApiUtil(org.jetbrains.plugins.github.api.GithubApiUtil) GithubNotifications(org.jetbrains.plugins.github.util.GithubNotifications) Nullable(org.jetbrains.annotations.Nullable) GithubUtil(org.jetbrains.plugins.github.util.GithubUtil) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) Project(com.intellij.openapi.project.Project) GitCloneDialog(git4idea.checkout.GitCloneDialog) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) CheckoutProvider(com.intellij.openapi.vcs.CheckoutProvider) GithubAuthDataHolder(org.jetbrains.plugins.github.util.GithubAuthDataHolder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Git(git4idea.commands.Git) GitCloneDialog(git4idea.checkout.GitCloneDialog) GithubRepo(org.jetbrains.plugins.github.api.data.GithubRepo) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ServiceManager (com.intellij.openapi.components.ServiceManager)1 Project (com.intellij.openapi.project.Project)1 CheckoutProvider (com.intellij.openapi.vcs.CheckoutProvider)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BasicAction (git4idea.actions.BasicAction)1 GitCheckoutProvider (git4idea.checkout.GitCheckoutProvider)1 GitCloneDialog (git4idea.checkout.GitCloneDialog)1 Git (git4idea.commands.Git)1 File (java.io.File)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 GithubApiUtil (org.jetbrains.plugins.github.api.GithubApiUtil)1 GithubRepo (org.jetbrains.plugins.github.api.data.GithubRepo)1 GithubAuthDataHolder (org.jetbrains.plugins.github.util.GithubAuthDataHolder)1 GithubNotifications (org.jetbrains.plugins.github.util.GithubNotifications)1 GithubUrlUtil (org.jetbrains.plugins.github.util.GithubUrlUtil)1