summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2020-02-07 11:05:44 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2020-02-10 10:48:39 +0100
commit009674e99f846d2dabe9b0776fc983f1df61886b (patch)
treeac262b9b444a6d9c10569c453cd3f44dc715419e /org.eclipse.jgit.test
parent9d1e47741780bf74ccd8a65643bc90791a5b0177 (diff)
parent75a80c5d3c790260a35ccf21ee54329f5d160879 (diff)
downloadjgit-009674e99f846d2dabe9b0776fc983f1df61886b.tar.gz
jgit-009674e99f846d2dabe9b0776fc983f1df61886b.zip
Merge branch 'stable-5.6'
* stable-5.6: Restore behavior of CloneCommand Change-Id: I3092bf214c41436b57e0ede9d2202f8aabf15471 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
index cee898ab86..3d0dacab3d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
@@ -408,6 +408,7 @@ public class CloneCommandTest extends RepositoryTestCase {
Git git2 = command.call();
addRepoToClose(git2.getRepository());
assertNotNull(git2);
+ assertTrue(git2.getRepository().isBare());
assertNotNull(git2.getRepository().resolve("tag-for-blob"));
assertNotNull(git2.getRepository().resolve("tag-initial"));
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
@@ -448,6 +449,60 @@ public class CloneCommandTest extends RepositoryTestCase {
specs.get(0));
}
+ @Test
+ public void testCloneRepositoryAllBranchesTakesPreference()
+ throws Exception {
+ File directory = createTempDirectory(
+ "testCloneRepositoryAllBranchesTakesPreference");
+ CloneCommand command = Git.cloneRepository();
+ command.setCloneAllBranches(true);
+ command.setBranchesToClone(
+ Collections.singletonList("refs/heads/test"));
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+ assertNotNull(git2);
+ assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test");
+ // Expect both remote branches to exist; setCloneAllBranches(true)
+ // should override any setBranchesToClone().
+ assertNotNull(
+ git2.getRepository().resolve("refs/remotes/origin/master"));
+ assertNotNull(git2.getRepository().resolve("refs/remotes/origin/test"));
+ RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(),
+ Constants.DEFAULT_REMOTE_NAME);
+ List<RefSpec> specs = cfg.getFetchRefSpecs();
+ assertEquals(1, specs.size());
+ assertEquals(new RefSpec("+refs/heads/*:refs/remotes/origin/*"),
+ specs.get(0));
+ }
+
+ @Test
+ public void testCloneRepositoryAllBranchesIndependent() throws Exception {
+ File directory = createTempDirectory(
+ "testCloneRepositoryAllBranchesIndependent");
+ CloneCommand command = Git.cloneRepository();
+ command.setCloneAllBranches(true);
+ command.setBranchesToClone(
+ Collections.singletonList("refs/heads/test"));
+ command.setCloneAllBranches(false);
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+ assertNotNull(git2);
+ assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test");
+ // Expect only the test branch; allBranches was re-set to false
+ assertNull(git2.getRepository().resolve("refs/remotes/origin/master"));
+ assertNotNull(git2.getRepository().resolve("refs/remotes/origin/test"));
+ RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(),
+ Constants.DEFAULT_REMOTE_NAME);
+ List<RefSpec> specs = cfg.getFetchRefSpecs();
+ assertEquals(1, specs.size());
+ assertEquals(new RefSpec("+refs/heads/test:refs/remotes/origin/test"),
+ specs.get(0));
+ }
+
public static String allRefNames(List<Ref> refs) {
StringBuilder sb = new StringBuilder();
for (Ref f : refs) {