aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Georgi2013-06-02 07:10:59 (EDT)
committerChristian Georgi2013-06-03 07:26:22 (EDT)
commit59f28c7c314a1ea76894f5a784c868e8e680ed26 (patch)
treec6bc319aec6ab925e22ff78b8b493c89d8aaab80
parentbacca11f85974cf4764fbdd79a6ccbdacdd4888f (diff)
downloadegit-59f28c7c314a1ea76894f5a784c868e8e680ed26.zip
egit-59f28c7c314a1ea76894f5a784c868e8e680ed26.tar.gz
egit-59f28c7c314a1ea76894f5a784c868e8e680ed26.tar.bz2
Consider URLs without user name when importing project setsrefs/changes/70/13470/3
Project set files usually do not contain user names, but remote URLs in repo configs often do. The opposite case might also happen, though more rarely: repo remote URL is anonymous, but project is not. Still consider these URLs (and thus the repos) the same. Bug: 409671 Change-Id: I52690c6e804181d848b9dff3f8851fb84636fd85
-rw-r--r--org.eclipse.egit.core.test/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitProjectSetCapabilityTest.java44
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java10
3 files changed, 55 insertions, 3 deletions
diff --git a/org.eclipse.egit.core.test/META-INF/MANIFEST.MF b/org.eclipse.egit.core.test/META-INF/MANIFEST.MF
index f92508b..e9ac611 100644
--- a/org.eclipse.egit.core.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.egit.core.test/META-INF/MANIFEST.MF
@@ -12,10 +12,10 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)",
org.hamcrest;bundle-version="[1.1.0,2.0.0)",
- org.junit;bundle-version="[4.3.0,5.0.0)",
- org.mockito;bundle-version="[1.8.0,1.9.0)"
+ org.junit;bundle-version="[4.3.0,5.0.0)"
Bundle-ActivationPolicy: lazy
Import-Package: org.mockito;version="[1.8.0,1.9.0)",
+ org.mockito.runners;version="[1.8.0,1.9.0)",
org.mockito.stubbing;version="[1.8.0,1.9.0)",
org.eclipse.egit.core;version="[3.0.0,3.1.0)",
org.eclipse.egit.core.op;version="[3.0.0,3.1.0)",
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitProjectSetCapabilityTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitProjectSetCapabilityTest.java
index abaae24..5e86e3b 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitProjectSetCapabilityTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/GitProjectSetCapabilityTest.java
@@ -14,6 +14,8 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@@ -260,6 +262,34 @@ public class GitProjectSetCapabilityTest {
root.getLocation().append("existingbutdifferent/repo/project"), imported.getLocation());
}
+ @Test
+ public void testImportFromRepoWithUrlOnlyDifferingInUserName()
+ throws Exception {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IPath reposPath = root.getLocation().append("repos");
+ pathsToClean.add(reposPath.toFile());
+
+ IPath repoPath = reposPath.append("repo");
+ IProject project = createProject(repoPath, "project");
+ project.delete(false, true, null);
+ String url = createUrl(repoPath, "ssh", "userName");
+ File repoDir = createRepository(repoPath, url, "master");
+
+ RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
+ util.addConfiguredRepository(repoDir);
+
+ String reference = createProjectReference(repoPath, "ssh", /* no user */
+ null, "master", "project");
+
+ addToWorkspace(new String[] { reference });
+
+ IProject imported = root.getProject("project");
+ assertEquals(
+ "Expected imported project to be from already existing repository. User name must be ignored in URL.",
+ root.getLocation().append("repos/repo/project"),
+ imported.getLocation());
+ }
+
private IProject createProject(String name) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject p = root.getProject(name);
@@ -311,10 +341,24 @@ public class GitProjectSetCapabilityTest {
return "1.0," + createUrl(repoPath) + "," + branch + "," + projectPath;
}
+ private static String createProjectReference(IPath repoPath,
+ String protocol, String user, String branch, String projectPath)
+ throws Exception {
+ return "1.0," + createUrl(repoPath, protocol, user) + "," + branch
+ + "," + projectPath;
+ }
+
private static String createUrl(IPath repoPath) {
return repoPath.toFile().toURI().toString();
}
+ private static String createUrl(IPath repoPath, String protocol, String user)
+ throws URISyntaxException {
+ URI uri = new URI(protocol, user, "localhost", 42, repoPath
+ .setDevice(null).makeAbsolute().toString(), null, null);
+ return uri.toString();
+ }
+
private void addToWorkspace(String[] references) throws TeamException {
capability.addToWorkspace(references,
new ProjectSetSerializationContext(),
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java
index bb15a72..fc15b29 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java
@@ -232,7 +232,8 @@ public class ProjectReferenceImporter {
return false;
}
- private static boolean containsRemoteForUrl(Config config, URIish url) throws URISyntaxException {
+ private static boolean containsRemoteForUrl(Config config, URIish url)
+ throws URISyntaxException {
Set<String> remotes = config.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);
for (String remote : remotes) {
String remoteUrl = config.getString(
@@ -242,6 +243,13 @@ public class ProjectReferenceImporter {
URIish existingUrl = new URIish(remoteUrl);
if (existingUrl.equals(url))
return true;
+
+ // try URLs without user name, since often project sets contain
+ // anonymous URLs, and remote URL might be anonymous as well
+ URIish anonExistingUrl = existingUrl.setUser(null);
+ URIish anonUrl = url.setUser(null);
+ if (anonExistingUrl.equals(anonUrl))
+ return true;
}
return false;
}