aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Trutz2011-06-28 23:33:23 (EDT)
committerKevin Sawicki2011-06-28 23:33:23 (EDT)
commitd751c5e61f31124f37d8cbff87980bed5a7b07b3 (patch)
tree9d3a70e27122918bc8b8805b7211da6178ec1485
parentb76ab59e124047ab677c83ddf9d65060a67aac26 (diff)
downloadegit-github-d751c5e61f31124f37d8cbff87980bed5a7b07b3.zip
egit-github-d751c5e61f31124f37d8cbff87980bed5a7b07b3.tar.gz
egit-github-d751c5e61f31124f37d8cbff87980bed5a7b07b3.tar.bz2
Clone GitHub repository via EGit.refs/changes/21/3721/7
GitHub repositories can be successfully be cloned (read-only) and are functional via EGit. Change-Id: I66f87acb61f3374730cc42fcac3174afb4953b4c Signed-off-by: Christian Trutz <christian.trutz@gmail.com> Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/Messages.java2
-rwxr-xr-xorg.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositoryImportWizard.java80
-rwxr-xr-xorg.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java16
-rw-r--r--org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/messages.properties1
4 files changed, 95 insertions, 4 deletions
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/Messages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/Messages.java
index 2f882ed..ce2a498 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/Messages.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/Messages.java
@@ -37,6 +37,8 @@ public class Messages extends NLS {
/** */
public static String CredentialsWizardPage_Title;
+ public static String RepositoryImportWizard_CloningRepository;
+
/** */
public static String RepositorySearchWizardPage_SearchButton;
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositoryImportWizard.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositoryImportWizard.java
index 62e9af7..e3f2ce3 100755
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositoryImportWizard.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositoryImportWizard.java
@@ -10,10 +10,31 @@
*******************************************************************************/
package org.eclipse.mylyn.internal.github.ui;
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.RepositoryUtil;
+import org.eclipse.egit.core.op.CloneOperation;
+import org.eclipse.egit.github.core.SearchRepository;
+import org.eclipse.egit.ui.UIPreferences;
+import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.transport.URIish;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
/**
* {@link IImportWizard} for cloning GitHub repositories.
@@ -21,6 +42,11 @@ import org.eclipse.ui.IWorkbench;
public class RepositoryImportWizard extends Wizard implements IImportWizard {
/**
+ *
+ */
+ private RepositorySearchWizardPage repositorySearchWizardPage = new RepositorySearchWizardPage();
+
+ /**
* {@inheritDoc}
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
@@ -31,7 +57,7 @@ public class RepositoryImportWizard extends Wizard implements IImportWizard {
*/
@Override
public void addPages() {
- addPage(new RepositorySearchWizardPage());
+ addPage(repositorySearchWizardPage);
}
/**
@@ -39,7 +65,57 @@ public class RepositoryImportWizard extends Wizard implements IImportWizard {
*/
@Override
public boolean performFinish() {
- // TODO clone GitHub repositotry via egit
+ try {
+ SearchRepository repository = repositorySearchWizardPage
+ .getRepository();
+ String repoName = repository.toString();
+ URIish uri = new URIish("git://github.com/" + repoName //$NON-NLS-1$
+ + Constants.DOT_GIT);
+ boolean allSelected = true;
+ Collection<Ref> selectedBranches = Collections.emptyList();
+ IPreferenceStore preferenceStore = org.eclipse.egit.ui.Activator
+ .getDefault().getPreferenceStore();
+ int timeout = preferenceStore
+ .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
+ String defaultRepoDir = preferenceStore
+ .getString(UIPreferences.DEFAULT_REPO_DIR);
+ final CloneOperation cloneOperation = new CloneOperation(uri,
+ allSelected, selectedBranches, new File(defaultRepoDir
+ + File.separator + repoName), Constants.R_HEADS
+ + Constants.MASTER, Constants.DEFAULT_REMOTE_NAME,
+ timeout);
+ Job job = new Job(Messages.RepositoryImportWizard_CloningRepository) {
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(
+ Messages.RepositoryImportWizard_CloningRepository,
+ 100);
+ cloneOperation.run(monitor);
+ monitor.worked(90);
+ RepositoryUtil repositoryUtil = Activator.getDefault()
+ .getRepositoryUtil();
+ monitor.worked(99);
+ repositoryUtil.addConfiguredRepository(cloneOperation
+ .getGitDir());
+ monitor.done();
+ } catch (InvocationTargetException invocationTargetException) {
+ GitHubUi.logError(invocationTargetException);
+ } catch (InterruptedException interruptedException) {
+ GitHubUi.logError(interruptedException);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.SHORT);
+ IWorkbenchSiteProgressService workbenchSiteProgressService = (IWorkbenchSiteProgressService) PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .getActivePart().getSite()
+ .getService(IWorkbenchSiteProgressService.class);
+ workbenchSiteProgressService.schedule(job);
+ } catch (URISyntaxException uriSyntaxException) {
+ GitHubUi.logError(uriSyntaxException);
+ return false;
+ }
return true;
}
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java
index c20191d..87b6654 100755
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/RepositorySearchWizardPage.java
@@ -17,7 +17,9 @@ import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.client.IGitHubConstants;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -44,6 +46,7 @@ public class RepositorySearchWizardPage extends WizardPage {
private Button searchButton;
private List repoList;
private ListViewer repoListViewer;
+ private SearchRepository repository = null;
/**
*
@@ -53,6 +56,10 @@ public class RepositorySearchWizardPage extends WizardPage {
setPageComplete(false);
}
+ protected SearchRepository getRepository() {
+ return repository;
+ }
+
/**
*
*/
@@ -113,8 +120,13 @@ public class RepositorySearchWizardPage extends WizardPage {
.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
- setPageComplete(!repoListViewer.getSelection()
- .isEmpty());
+ ISelection selection = repoListViewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ repository = (SearchRepository) structuredSelection
+ .getFirstElement();
+ }
+ setPageComplete(!selection.isEmpty());
}
});
diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/messages.properties b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/messages.properties
index 73c00cd..db25f51 100644
--- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/messages.properties
+++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/messages.properties
@@ -4,6 +4,7 @@ CredentialsWizardPage_ErrorUser=Enter GitHub login name
CredentialsWizardPage_LabelPassword=Password:
CredentialsWizardPage_LabelUser=User ID:
CredentialsWizardPage_Title=GitHub Credentials
+RepositoryImportWizard_CloningRepository=Cloning GitHub repository...
RepositorySearchWizardPage_SearchButton=Search
RepositorySearchWizardPage_SearchForRepositories=Search for repositories that have to do with:
RepositorySelectionWizardPage_Description=Select repositories to import