Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/T0003_AdaptableFileTreeIteratorTest.java2
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/mapping/T0002_history.java2
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/op/T0001_ConnectProviderOperationTest.java6
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java57
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java22
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java29
6 files changed, 99 insertions, 19 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/T0003_AdaptableFileTreeIteratorTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/T0003_AdaptableFileTreeIteratorTest.java
index f7a501a1e1..3808edbef1 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/T0003_AdaptableFileTreeIteratorTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/T0003_AdaptableFileTreeIteratorTest.java
@@ -47,7 +47,7 @@ public class T0003_AdaptableFileTreeIteratorTest extends GitTestCase {
fileWriter.close();
final ConnectProviderOperation operation = new ConnectProviderOperation(
- project.getProject());
+ project.getProject(), new File("../.git"));
operation.run(null);
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/mapping/T0002_history.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/mapping/T0002_history.java
index d2a6c937fa..feab40a54f 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/mapping/T0002_history.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/mapping/T0002_history.java
@@ -101,7 +101,7 @@ public class T0002_history extends GitTestCase {
assertEquals(RefUpdate.Result.NEW, lck.forceUpdate());
ConnectProviderOperation operation = new ConnectProviderOperation(
- project.getProject());
+ project.getProject(), new File("../.git"));
operation.run(null);
}
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/op/T0001_ConnectProviderOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/op/T0001_ConnectProviderOperationTest.java
index a5a9a1665a..eac2aabf45 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/op/T0001_ConnectProviderOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/op/T0001_ConnectProviderOperationTest.java
@@ -37,7 +37,7 @@ public class T0001_ConnectProviderOperationTest extends GitTestCase {
public void testNoRepository() throws CoreException {
ConnectProviderOperation operation = new ConnectProviderOperation(
- project.getProject());
+ project.getProject(), new File("../../.git"));
operation.run(null);
assertFalse(RepositoryProvider.isShared(project.getProject()));
@@ -52,7 +52,7 @@ public class T0001_ConnectProviderOperationTest extends GitTestCase {
repository.create();
repository.close();
ConnectProviderOperation operation = new ConnectProviderOperation(
- project.getProject());
+ project.getProject(), new File("../.git"));
operation.run(null);
assertTrue(RepositoryProvider.isShared(project.getProject()));
@@ -94,7 +94,7 @@ public class T0001_ConnectProviderOperationTest extends GitTestCase {
assertEquals(RefUpdate.Result.NEW, lck.forceUpdate());
ConnectProviderOperation operation = new ConnectProviderOperation(
- project.getProject());
+ project.getProject(), new File("../.git"));
operation.run(null);
final boolean f[] = new boolean[1];
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
index 33ccb21a6a..627a5f4a05 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/ConnectProviderOperation.java
@@ -1,6 +1,7 @@
/*******************************************************************************
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
* Copyright (C) 2008, Google Inc.
+ * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,7 +10,12 @@
*******************************************************************************/
package org.eclipse.egit.core.op;
+import java.io.File;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -31,16 +37,31 @@ import org.eclipse.team.core.RepositoryProvider;
* Connects Eclipse to an existing Git repository
*/
public class ConnectProviderOperation implements IWorkspaceRunnable {
- private final IProject[] projects;
+ private final Map<IProject, File> projects = new HashMap<IProject, File>();
/**
* Create a new connection operation to execute within the workspace.
+ * <p>
+ * Uses <code>.git</code> as a default relative path to repository.
+ * @see #ConnectProviderOperation(IProject, File)
*
* @param proj
* the project to connect to the Git team provider.
*/
public ConnectProviderOperation(final IProject proj) {
- this(new IProject[] { proj });
+ this(proj, new File(".git"));
+ }
+
+ /**
+ * Create a new connection operation to execute within the workspace.
+ *
+ * @param proj
+ * the project to connect to the Git team provider.
+ * @param pathToRepo
+ * relative path to the repository
+ */
+ public ConnectProviderOperation(final IProject proj, File pathToRepo) {
+ this.projects.put(proj, pathToRepo);
}
/**
@@ -49,8 +70,8 @@ public class ConnectProviderOperation implements IWorkspaceRunnable {
* @param projects
* the projects to connect to the Git team provider.
*/
- public ConnectProviderOperation(final IProject[] projects) {
- this.projects = projects;
+ public ConnectProviderOperation(final Map<IProject, File> projects) {
+ this.projects.putAll(projects);
}
public void run(IProgressMonitor m) throws CoreException {
@@ -59,20 +80,23 @@ public class ConnectProviderOperation implements IWorkspaceRunnable {
}
m.beginTask(CoreText.ConnectProviderOperation_connecting,
- 100 * projects.length);
+ 100 * projects.size());
try {
- for (IProject project : projects) {
+ for (Iterator iterator = projects.keySet().iterator(); iterator.hasNext();) {
+ IProject project = (IProject) iterator.next();
m.setTaskName(NLS.bind(
CoreText.ConnectProviderOperation_ConnectingProject,
project.getName()));
Activator.trace("Locating repository for " + project); //$NON-NLS-1$
Collection<RepositoryMapping> repos = new RepositoryFinder(
project).find(new SubProgressMonitor(m, 40));
- if (repos.size() == 1) {
+ File suggestedRepo = projects.get(project);
+ RepositoryMapping actualMapping= findActualRepository(repos, suggestedRepo);
+ if (actualMapping != null) {
GitProjectData projectData = new GitProjectData(project);
try {
- projectData.setRepositoryMappings(repos);
+ projectData.setRepositoryMappings(Arrays.asList(actualMapping));
projectData.store();
} catch (CoreException ce) {
GitProjectData.delete(project);
@@ -98,4 +122,21 @@ public class ConnectProviderOperation implements IWorkspaceRunnable {
m.done();
}
}
+
+ /**
+ * @param repos
+ * available repositories
+ * @param suggestedRepo
+ * relative path to git repository
+ * @return a repository mapping which corresponds to a suggested repository
+ * location, <code>null</code> otherwise
+ */
+ private RepositoryMapping findActualRepository(
+ Collection<RepositoryMapping> repos, File suggestedRepo) {
+ for (RepositoryMapping rm : repos) {
+ if (rm.getGitDir().equals(suggestedRepo.getPath()))
+ return rm;
+ }
+ return null;
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java
index c5592ce277..f988aa2405 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java
@@ -4,6 +4,7 @@ package org.eclipse.egit.ui.internal.clone;
* Copyright (c) 2004, 2008 IBM Corporation and others.
* Copyright (C) 2007, Martin Oberhuber (martin.oberhuber@windriver.com)
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -94,6 +95,12 @@ public class GitProjectsImportPage extends WizardPage {
IProjectDescription description;
/**
+ * Relative path to repository, '../.git' is by default. If you'll set
+ * it null you're on your own, no checks for null performed.
+ */
+ File repository = new File("../.git"); //$NON-NLS-1$
+
+ /**
* Create a record for a project based on the info in the file.
*
* @param file
@@ -104,6 +111,19 @@ public class GitProjectsImportPage extends WizardPage {
}
/**
+ * Create a record for a project based on the info in the file.
+ *
+ * @param file
+ * @param aRepository
+ * relative path to repository
+ */
+ ProjectRecord(File file, File aRepository) {
+ projectSystemFile = file;
+ setProjectName();
+ repository = aRepository;
+ }
+
+ /**
* @param parent
* The parent folder of the .project file
* @param level
@@ -712,7 +732,7 @@ public class GitProjectsImportPage extends WizardPage {
monitor, openTicks));
if (share) {
ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation(
- project);
+ project, record.repository);
connectProviderOperation
.run(new SubProgressMonitor(monitor, 20));
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java
index c546e3cbff..87893278f4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/sharing/ExistingOrNewPage.java
@@ -1,5 +1,6 @@
/*******************************************************************************
* Copyright (C) 2009, Robin Rosenberg
+ * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,8 +11,11 @@ package org.eclipse.egit.ui.internal.sharing;
import java.io.File;
import java.io.IOException;
+import java.net.URI;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -121,7 +125,7 @@ class ExistingOrNewPage extends WizardPage {
try {
Repository repository = new Repository(gitDir);
repository.create();
- for (IProject project : getProjects()) {
+ for (IProject project : getProjects().keySet()) {
// If we don't refresh the project directories right
// now we won't later know that a .git directory
// exists within it and we won't mark the .git
@@ -228,10 +232,25 @@ class ExistingOrNewPage extends WizardPage {
return true;
}
- public IProject[] getProjects() {
- IProject[] ret = new IProject[tree.getSelection().length];
- for (int i = 0; i < ret.length; ++i)
- ret[i] = (IProject)tree.getSelection()[i].getData();
+ /**
+ * @return map between project and repository root directory (converted to a
+ * path relative to project's root) for all projects selected by
+ * user
+ */
+ public Map<IProject, File> getProjects() {
+ final TreeItem[] selection = tree.getSelection();
+ Map<IProject, File> ret = new HashMap<IProject, File>(selection.length);
+ for (int i = 0; i < selection.length; ++i) {
+ final TreeItem treeItem = selection[i];
+ final IProject project = (IProject) treeItem.getData();
+ final File selectedRepo = new File(treeItem.getText(2));
+ File localPathToRepo = selectedRepo;
+ if (selectedRepo.isAbsolute()) {
+ final URI projectLocation = project.getLocationURI();
+ localPathToRepo = new File(projectLocation.relativize(selectedRepo.toURI()).getPath());
+ }
+ ret.put(project, localPathToRepo);
+ }
return ret;
}
}

Back to the top