aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorYuxuan 'fishy' Wang <fishywang@google.com>2015-07-09 22:12:28 -0700
committerYuxuan 'fishy' Wang <fishywang@google.com>2015-07-10 11:39:26 -0700
commit217b2a7cc5366491be5317d20f3f3c1b6e3475bf (patch)
tree64e39844d8495241202d5f40021a4a1e28f1df43 /org.eclipse.jgit.test
parent37a1e4beaa9e31e642be3aef645f060eb96b1b86 (diff)
downloadjgit-217b2a7cc5366491be5317d20f3f3c1b6e3475bf.tar.gz
jgit-217b2a7cc5366491be5317d20f3f3c1b6e3475bf.zip
Add setTargetBranch in RepoCommand.
This will allow us to write the super project in a branch other than master. Change-Id: I578ed9ecbc6423416239e31ad644531dae9fb5c3 Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java81
1 files changed, 51 insertions, 30 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 3d86cfd5bb..66e7256432 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
@@ -241,9 +241,9 @@ public class RepoCommandTest extends RepositoryTestCase {
@Test
public void testBareRepo() throws Exception {
- Repository remoteDb = createBareRepository();
- Repository tempDb = createWorkRepository();
- try {
+ try (
+ Repository remoteDb = createBareRepository();
+ Repository tempDb = createWorkRepository()) {
StringBuilder xmlContent = new StringBuilder();
xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
@@ -280,9 +280,6 @@ public class RepoCommandTest extends RepositoryTestCase {
String remote = defaultDb.resolve(Constants.HEAD).name();
assertEquals("The gitlink should be the same as remote head",
remote, gitlink);
- } finally {
- tempDb.close();
- remoteDb.close();
}
}
@@ -366,9 +363,9 @@ public class RepoCommandTest extends RepositoryTestCase {
@Test
public void testRevisionBare() throws Exception {
- Repository remoteDb = createBareRepository();
- Repository tempDb = createWorkRepository();
- try {
+ try (
+ Repository remoteDb = createBareRepository();
+ Repository tempDb = createWorkRepository()) {
StringBuilder xmlContent = new StringBuilder();
xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
.append("<manifest>")
@@ -393,17 +390,14 @@ public class RepoCommandTest extends RepositoryTestCase {
localDb.close();
assertEquals("The gitlink is same as remote head",
oldCommitId.name(), gitlink);
- } finally {
- tempDb.close();
- remoteDb.close();
}
}
@Test
public void testCopyFileBare() throws Exception {
- Repository remoteDb = createBareRepository();
- Repository tempDb = createWorkRepository();
- try {
+ try (
+ Repository remoteDb = createBareRepository();
+ Repository tempDb = createWorkRepository()) {
StringBuilder xmlContent = new StringBuilder();
xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
@@ -435,17 +429,14 @@ public class RepoCommandTest extends RepositoryTestCase {
reader.close();
assertEquals("The Hello file should have expected content",
"branch world", content);
- } finally {
- tempDb.close();
- remoteDb.close();
}
}
@Test
public void testReplaceManifestBare() throws Exception {
- Repository remoteDb = createBareRepository();
- Repository tempDb = createWorkRepository();
- try {
+ try (
+ Repository remoteDb = createBareRepository();
+ Repository tempDb = createWorkRepository()) {
StringBuilder xmlContent = new StringBuilder();
xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
@@ -512,17 +503,14 @@ public class RepoCommandTest extends RepositoryTestCase {
reader.close();
assertTrue("The bar submodule should exist", bar);
assertFalse("The foo submodule shouldn't exist", foo);
- } finally {
- tempDb.close();
- remoteDb.close();
}
}
@Test
public void testRemoveOverlappingBare() throws Exception {
- Repository remoteDb = createBareRepository();
- Repository tempDb = createWorkRepository();
- try {
+ try (
+ Repository remoteDb = createBareRepository();
+ Repository tempDb = createWorkRepository()) {
StringBuilder xmlContent = new StringBuilder();
xmlContent
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
@@ -571,9 +559,6 @@ public class RepoCommandTest extends RepositoryTestCase {
assertTrue("The foo submodule should exist", foo);
assertFalse("The foo/bar submodule shouldn't exist", foobar);
assertTrue("The a submodule should exist", a);
- } finally {
- tempDb.close();
- remoteDb.close();
}
}
@@ -671,6 +656,42 @@ public class RepoCommandTest extends RepositoryTestCase {
assertTrue("We should have foo", file.exists());
}
+ @Test
+ public void testTargetBranch() throws Exception {
+ try (
+ Repository remoteDb1 = createBareRepository();
+ Repository remoteDb2 = createBareRepository();
+ Repository tempDb = createWorkRepository()) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent
+ .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\".\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"foo\" name=\"").append(defaultUri)
+ .append("\" />").append("</manifest>");
+ JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
+ xmlContent.toString());
+ RepoCommand command = new RepoCommand(remoteDb1);
+ command
+ .setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+ .setURI(rootUri)
+ .setTargetBranch("test")
+ .call();
+ ObjectId branchId = remoteDb1.resolve(
+ Constants.R_HEADS + "test^{tree}");
+ command = new RepoCommand(remoteDb2);
+ command
+ .setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+ .setURI(rootUri)
+ .call();
+ ObjectId defaultId = remoteDb2.resolve(Constants.HEAD + "^{tree}");
+ assertEquals(
+ "The tree id of branch db and default db should be the same",
+ branchId, defaultId);
+ }
+ }
+
private void resolveRelativeUris() {
// Find the longest common prefix ends with "/" as rootUri.
defaultUri = defaultDb.getDirectory().toURI().toString();