summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMykola Nikishov2009-10-20 09:52:20 (EDT)
committer Shawn O. Pearce2009-11-30 20:35:05 (EST)
commitcb9adcf59464fc49a555516039435c45eb6ccb60 (patch)
tree5300b8906a1198b20af2629eea359cd61e827dff
parente1c95778f0db4015967d784c203a7cd4d18441cc (diff)
downloadegit-cb9adcf59464fc49a555516039435c45eb6ccb60.zip
egit-cb9adcf59464fc49a555516039435c45eb6ccb60.tar.gz
egit-cb9adcf59464fc49a555516039435c45eb6ccb60.tar.bz2
ConnectProviderOperation uses git repositories selected by userrefs/changes/84/84/4
ConnectProviderOperation tried to connect only projects provided by getProjects() method in ExistingOrNewPage. This method returned only a list of projects, and the mapping between the project and its git repository directory is never used and lost. ConnectProviderOperation tried to find repository itself using RepositoryFinder's method find(IProgressMonitor). The logic of this method was fixed and it returns more then one RepositoryMapping for a project nested into other git repository. But this isn't expected by ConnectProviderOperation and it wouldn't even try to connect such project. Now: - method getProjects() in ExistingOrNewPage now returns a pairing, Map<IProject, File> instead of IProject[]. It provides information about git repositories which has been selected by user for each project. If a git repository path is absolute (it was just created) it will make it relative to the project's root. - ConnectProviderOperation uses Map<IProject, File> instead of IProject[] and will connect project to git repository only if it has been founded in repository mappings provided by method find(IProgressMonitor) for a given project. - default value '../.git' provided for just introduced field GitProjectsImportPage.ProjectRecord.repository - path to a test repository in unit tests Bug: 291303 Change-Id: Id6f30efd6a4d10a4f1946e92dc54e51972166be9 Signed-off-by: Mykola Nikishov <mn@mn.com.ua> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-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 f7a501a..3808edb 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 d2a6c93..feab40a 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 a5a9a16..eac2aab 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 33ccb21..627a5f4 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 c5592ce..f988aa2 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 c546e3c..8789327 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;
}
}