Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Georgi2015-02-10 14:01:20 +0000
committerChristian Georgi2015-02-11 11:10:07 +0000
commita5e5cef0629aa6752854ed272aa7d3b613d6b91b (patch)
treecc46f165f776659544fe29d49b66c37b1e12caf8
parent8820b8acd84c3967b79fd6c01f1615aaeca18901 (diff)
downloadegit-a5e5cef0629aa6752854ed272aa7d3b613d6b91b.tar.gz
egit-a5e5cef0629aa6752854ed272aa7d3b613d6b91b.tar.xz
egit-a5e5cef0629aa6752854ed272aa7d3b613d6b91b.zip
Consider different users and repo suffixes in project importer
Two URLs differing in users *and* repo suffixes (.git) should be treated the same. This was not handled properly with the last fix for bug 453892. In addition there is now also test cases for the relevant parts of ProjectReferenceImporter. Bug: 459551 Change-Id: I5308d089996cfc1be3a13120ef50e6cf23c5cf42 Signed-off-by: Christian Georgi <christian.georgi@sap.com>
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java117
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java7
2 files changed, 121 insertions, 3 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java
new file mode 100644
index 0000000000..cba88e6efa
--- /dev/null
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/internal/ProjectReferenceImporterTest.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (C) 2015, Christian Georgi (SAP SE)
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.core.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.core.RepositoryUtil;
+import org.eclipse.egit.core.test.GitTestCase;
+import org.eclipse.egit.core.test.TestRepository;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.transport.URIish;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ProjectReferenceImporter}
+ */
+public class ProjectReferenceImporterTest extends GitTestCase {
+
+ private TestRepository testRepository;
+
+ private Repository repository;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ testRepository = new TestRepository(gitDir);
+ repository = testRepository.getRepository();
+ RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
+ util.addConfiguredRepository(repository.getDirectory());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
+ util.removeDir(repository.getDirectory());
+ testRepository.dispose();
+ repository = null;
+ super.tearDown();
+ }
+
+ @Test
+ public void findRepository_SameURLs() throws Exception {
+ addRemote(repository, "origin", uri("ssh://user@host.com:42/repo"));
+
+ File foundRepo = ProjectReferenceImporter
+ .findConfiguredRepository(uri("ssh://user@host.com:42/repo"));
+ assertEquals(repository.getDirectory(), foundRepo);
+ }
+
+ @Test
+ public void findRepository_MultipleRemotes() throws Exception {
+ addRemote(repository, "remote_1", uri("ssh://user@host.com:42/repo"));
+ addRemote(repository, "remote_2", uri("http://host.com/other/repo"));
+
+ File foundRepo = ProjectReferenceImporter
+ .findConfiguredRepository(uri("ssh://user@host.com:42/repo"));
+ assertEquals(repository.getDirectory(), foundRepo);
+ }
+
+ @Test
+ public void findRepository_DifferentUsers() throws Exception {
+ addRemote(repository, "origin", uri("ssh://user_1@host.com:42/repo"));
+
+ File foundRepo = ProjectReferenceImporter
+ .findConfiguredRepository(uri("ssh://user_2@host.com:42/repo"));
+ assertEquals(repository.getDirectory(), foundRepo);
+
+ foundRepo = ProjectReferenceImporter
+ .findConfiguredRepository(uri("ssh://host.com:42/repo"));
+ assertEquals(repository.getDirectory(), foundRepo);
+ }
+
+ @Test
+ public void findRepository_DifferentUsersAndRepoSuffixes() throws Exception {
+ addRemote(repository, "origin", uri("ssh://user_1@host.com:42/repo"));
+
+ File foundRepo = ProjectReferenceImporter
+ .findConfiguredRepository(uri("ssh://user_2@host.com:42/repo.git"));
+ assertEquals(repository.getDirectory(), foundRepo);
+ }
+
+ @Test
+ public void findRepository_DifferentRepos() throws Exception {
+ addRemote(repository, "origin", uri("ssh://host.com:42/repo_1"));
+
+ File foundRepo = ProjectReferenceImporter
+ .findConfiguredRepository(uri("ssh://host.com:42/repo_2"));
+ assertNotEquals(repository.getDirectory(), foundRepo);
+ }
+
+ private static void addRemote(Repository repository, String name, URIish url)
+ throws IOException {
+ StoredConfig config = repository.getConfig();
+ config.setString("remote", name, "url", url.toString());
+ config.save();
+ }
+
+ private static URIish uri(String s) throws URISyntaxException {
+ return new URIish(s);
+ }
+
+}
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 eafd1f05fc..2c9fba7937 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2011, 2012 Robin Stocker <robin@nibor.org>
+ * Copyright (C) 2011, 2015 Robin Stocker <robin@nibor.org>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -199,7 +199,7 @@ public class ProjectReferenceImporter {
return workDir;
}
- private static File findConfiguredRepository(URIish gitUrl) {
+ static File findConfiguredRepository(URIish gitUrl) {
for (String repoDir : getRepositoryUtil().getConfiguredRepositories()) {
File repoDirFile = new File(repoDir);
if (repositoryAlreadyExistsForUrl(repoDirFile, gitUrl))
@@ -260,7 +260,8 @@ public class ProjectReferenceImporter {
// some URLs end with .git, some don't
String path = existingUrl.getPath();
if (path.endsWith(".git")) { //$NON-NLS-1$
- newURL = existingUrl.setPath(path.substring(0,
+ newURL = newURL
+ .setPath(path.substring(0,
path.lastIndexOf(".git"))); //$NON-NLS-1$
}

Back to the top