diff options
author | Han-Wen Nienhuys <hanwen@google.com> | 2018-02-19 19:59:35 +0100 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@google.com> | 2018-02-21 13:41:50 +0100 |
commit | 6a420613f7dae0f58496e259859d1a6cf1965f5b (patch) | |
tree | ea432ee9612e58596ff62a98ffb7e97cb5f665b4 /org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo | |
parent | 3214171decf596f003c154685638b01faba31ff3 (diff) | |
download | jgit-6a420613f7dae0f58496e259859d1a6cf1965f5b.tar.gz jgit-6a420613f7dae0f58496e259859d1a6cf1965f5b.zip |
RepoCommand: generate relative submodule URLs from absolute URLs.
If a manifest file specifies an absolute URL on the same host on which
the superproject resides, rewrite the URLs to be relative.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Id616611e5195998fb665c8e7806539a3a02e219a
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index f4b86e0ce6..2253a0421f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -439,6 +439,63 @@ public class RepoCommandTest extends RepositoryTestCase { } @Test + public void absoluteRemoteURLAbsoluteTargetURL() throws Exception { + Repository child = + Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString()) + .setDirectory(createUniqueTestGitDir(true)) + .setBare(true).call().getRepository(); + Repository dest = Git.cloneRepository() + .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true)) + .setBare(true).call().getRepository(); + String abs = "https://chromium.googlesource.com"; + String repoUrl = "https://chromium.googlesource.com/chromium/src"; + boolean fetchSlash = false; + boolean baseSlash = false; + do { + do { + String fetchUrl = fetchSlash ? abs + "/" : abs; + String baseUrl = baseSlash ? abs + "/" : abs; + + StringBuilder xmlContent = new StringBuilder(); + xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") + .append("<manifest>") + .append("<remote name=\"origin\" fetch=\"" + fetchUrl + "\" />") + .append("<default revision=\"master\" remote=\"origin\" />") + .append("<project path=\"src\" name=\"chromium/src\" />") + .append("</manifest>"); + RepoCommand cmd = new RepoCommand(dest); + + IndexedRepos repos = new IndexedRepos(); + repos.put(repoUrl, child); + + RevCommit commit = cmd + .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))) + .setRemoteReader(repos) + .setURI(baseUrl) + .setTargetURI(abs + "/superproject") + .setRecordRemoteBranch(true) + .setRecordSubmoduleLabels(true) + .call(); + + String idStr = commit.getId().name() + ":" + ".gitmodules"; + ObjectId modId = dest.resolve(idStr); + + try (ObjectReader reader = dest.newObjectReader()) { + byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE); + Config base = new Config(); + BlobBasedConfig cfg = new BlobBasedConfig(base, bytes); + String subUrl = cfg.getString("submodule", "src", "url"); + assertEquals("../chromium/src", subUrl); + } + fetchSlash = !fetchSlash; + } while (fetchSlash); + baseSlash = !baseSlash; + } while (baseSlash); + child.close(); + dest.close(); + } + + @Test public void testAddRepoManifest() throws Exception { StringBuilder xmlContent = new StringBuilder(); xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") @@ -1188,5 +1245,6 @@ public class RepoCommandTest extends RepositoryTestCase { testRelative("abc", "/bcd", "/bcd"); testRelative("http://a", "a/b", "a/b"); testRelative("http://base.com/a/", "http://child.com/a/b", "http://child.com/a/b"); + testRelative("http://base.com/a/", "http://base.com/a/b", "b"); } } |