Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuxuan 'fishy' Wang2014-08-18 17:57:09 +0000
committerYuxuan 'fishy' Wang2014-08-18 17:57:09 +0000
commit5a26c538b392c1dbcb81783e9173db603a88f44f (patch)
tree8de997b5d9f64a6a50e57caa71f6b57789eec8d5
parent8e19fea1a9fb222d09b3fc32b1c71c86ff07e7cd (diff)
downloadjgit-5a26c538b392c1dbcb81783e9173db603a88f44f.tar.gz
jgit-5a26c538b392c1dbcb81783e9173db603a88f44f.tar.xz
jgit-5a26c538b392c1dbcb81783e9173db603a88f44f.zip
Support non-default remotes in project tag.
Change-Id: I3c730a1ce379d142d3ed81dda4a73f86f1f9c3eb Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java30
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java32
2 files changed, 53 insertions, 9 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 41a086f6be..5f2aece47e 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
@@ -611,6 +611,36 @@ public class RepoCommandTest extends RepositoryTestCase {
"master world", content);
}
+ @Test
+ public void testNonDefaultRemotes() throws Exception {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\".\" />")
+ .append("<remote name=\"remote2\" fetch=\"")
+ .append(notDefaultUri)
+ .append("\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"foo\" name=\"")
+ .append(defaultUri)
+ .append("\" />")
+ .append("<project path=\"bar\" name=\".\" remote=\"remote2\" />")
+ .append("</manifest>");
+
+ Repository localDb = createWorkRepository();
+ JGitTestUtil.writeTrashFile(
+ localDb, "manifest.xml", xmlContent.toString());
+ RepoCommand command = new RepoCommand(localDb);
+ command
+ .setPath(localDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+ .setURI(rootUri)
+ .call();
+ File file = new File(localDb.getWorkTree(), "foo/hello.txt");
+ assertTrue("We should have foo", file.exists());
+ file = new File(localDb.getWorkTree(), "bar/world.txt");
+ assertTrue("We should have bar", file.exists());
+ }
+
private void resolveRelativeUris() {
// Find the longest common prefix ends with "/" as rootUri.
defaultUri = defaultDb.getDirectory().toURI().toString();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
index 0350e1c0fc..3bf3c18840 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
@@ -281,13 +281,16 @@ public class RepoCommand extends GitCommand<RevCommit> {
final String name;
final String path;
final String revision;
+ final String remote;
final Set<String> groups;
final List<CopyFile> copyfiles;
- Project(String name, String path, String revision, String groups) {
+ Project(String name, String path, String revision,
+ String remote, String groups) {
this.name = name;
this.path = path;
this.revision = revision;
+ this.remote = remote;
this.groups = new HashSet<String>();
if (groups != null && groups.length() > 0)
this.groups.addAll(Arrays.asList(groups.split(","))); //$NON-NLS-1$
@@ -401,6 +404,7 @@ public class RepoCommand extends GitCommand<RevCommit> {
attributes.getValue("name"), //$NON-NLS-1$
attributes.getValue("path"), //$NON-NLS-1$
attributes.getValue("revision"), //$NON-NLS-1$
+ attributes.getValue("remote"), //$NON-NLS-1$
attributes.getValue("groups")); //$NON-NLS-1$
} else if ("remote".equals(qName)) { //$NON-NLS-1$
remotes.put(attributes.getValue("name"), //$NON-NLS-1$
@@ -474,18 +478,28 @@ public class RepoCommand extends GitCommand<RevCommit> {
else
throw new SAXException(RepoText.get().errorNoDefault);
}
- String remoteUrl;
+ removeNotInGroup();
+ removeOverlaps();
+
+ Map<String, String> remoteUrls = new HashMap<String, String>();
+ URI baseUri;
try {
- URI uri = new URI(baseUrl);
- remoteUrl = uri.resolve(remotes.get(defaultRemote)).toString();
- if (!remoteUrl.endsWith("/"))
- remoteUrl = remoteUrl + "/";
+ baseUri = new URI(baseUrl);
} catch (URISyntaxException e) {
throw new SAXException(e);
}
- removeNotInGroup();
- removeOverlaps();
for (Project proj : projects) {
+ String remote = proj.remote;
+ if (remote == null)
+ remote = defaultRemote;
+ String remoteUrl = remoteUrls.get(remote);
+ if (remoteUrl == null) {
+ remoteUrl = baseUri.resolve(remotes.get(remote)).toString();
+ if (!remoteUrl.endsWith("/"))
+ remoteUrl = remoteUrl + "/";
+ remoteUrls.put(remote, remoteUrl);
+ }
+
command.addSubmodule(remoteUrl + proj.name,
proj.path,
proj.revision == null
@@ -819,7 +833,7 @@ public class RepoCommand extends GitCommand<RevCommit> {
private void addSubmodule(String url, String name, String revision,
List<CopyFile> copyfiles) throws SAXException {
if (repo.isBare()) {
- Project proj = new Project(url, name, revision, null);
+ Project proj = new Project(url, name, revision, null, null);
proj.copyfiles.addAll(copyfiles);
bareProjects.add(proj);
} else {

Back to the top