summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2011-05-24 00:45:21 +0200
committerShawn O. Pearce <spearce@spearce.org>2011-05-31 08:58:45 -0700
commitcc2197ed9c3be35c875c8316f17a2d6e8d338c88 (patch)
treea124cc1028b294fd082471a5700a75963f71e142 /org.eclipse.jgit.test
parentcc319fff0db7e23e244fe650f4102150da5633d5 (diff)
downloadjgit-cc2197ed9c3be35c875c8316f17a2d6e8d338c88.tar.gz
jgit-cc2197ed9c3be35c875c8316f17a2d6e8d338c88.zip
Fix CloneCommand not to fetch into remote tracking branches when bare
When cloning into a bare repository we should not create remote tracking branches (e.g refs/remotes/origin/testX). Branches of the remote repository should but fetched into into branches of the same name (e.g refs/heads/testX). Also add the noCheckout option which would prevent checkout after fetch. Change-Id: I5d4cc0389f3f30c53aa0065f38119af2a1430909 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java70
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java4
2 files changed, 70 insertions, 4 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 f21dc4a0be..9d01291b7a 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
@@ -49,12 +49,14 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
+import java.util.List;
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
@@ -136,6 +138,42 @@ public class CloneCommandTest extends RepositoryTestCase {
assertNotNull(git2);
assertEquals(git2.getRepository().getFullBranch(),
"refs/heads/master");
+ assertEquals(
+ "refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test",
+ allRefNames(git2.branchList().setListMode(ListMode.ALL)
+ .call()));
+
+ // Same thing, but now without checkout
+ directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
+ command = Git.cloneRepository();
+ command.setBranch("refs/heads/master");
+ command.setDirectory(directory);
+ command.setURI("file://"
+ + git.getRepository().getWorkTree().getPath());
+ command.setNoCheckout(true);
+ git2 = command.call();
+ assertNotNull(git2);
+ assertEquals(git2.getRepository().getFullBranch(),
+ "refs/heads/master");
+ assertEquals(
+ "refs/remotes/origin/master, refs/remotes/origin/test",
+ allRefNames(git2.branchList().setListMode(ListMode.ALL)
+ .call()));
+
+ // Same thing, but now test with bare repo
+ directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
+ command = Git.cloneRepository();
+ command.setBranch("refs/heads/master");
+ command.setDirectory(directory);
+ command.setURI("file://"
+ + git.getRepository().getWorkTree().getPath());
+ command.setBare(true);
+ git2 = command.call();
+ assertNotNull(git2);
+ assertEquals(git2.getRepository().getFullBranch(),
+ "refs/heads/master");
+ assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2
+ .branchList().setListMode(ListMode.ALL).call()));
} catch (Exception e) {
fail(e.getMessage());
}
@@ -156,13 +194,41 @@ public class CloneCommandTest extends RepositoryTestCase {
assertNotNull(git2);
assertEquals(git2.getRepository().getFullBranch(),
"refs/heads/master");
- assertEquals(1, git2.branchList().setListMode(ListMode.REMOTE)
- .call().size());
+ assertEquals("refs/remotes/origin/master",
+ allRefNames(git2.branchList()
+ .setListMode(ListMode.REMOTE).call()));
+
+ // Same thing, but now test with bare repo
+ directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
+ command = Git.cloneRepository();
+ command.setBranch("refs/heads/master");
+ command.setBranchesToClone(Collections
+ .singletonList("refs/heads/master"));
+ command.setDirectory(directory);
+ command.setURI("file://"
+ + git.getRepository().getWorkTree().getPath());
+ command.setBare(true);
+ git2 = command.call();
+ assertNotNull(git2);
+ assertEquals(git2.getRepository().getFullBranch(),
+ "refs/heads/master");
+ assertEquals("refs/heads/master", allRefNames(git2
+ .branchList().setListMode(ListMode.ALL).call()));
} catch (Exception e) {
fail(e.getMessage());
}
}
+ public static String allRefNames(List<Ref> refs) {
+ StringBuilder sb = new StringBuilder();
+ for (Ref f : refs) {
+ if (sb.length() > 0)
+ sb.append(", ");
+ sb.append(f.getName());
+ }
+ return sb.toString();
+ }
+
public static File createTempDirectory(String name) throws IOException {
final File temp;
temp = File.createTempFile(name, Long.toString(System.nanoTime()));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
index 0e0b18732b..b6ba4c927d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
@@ -79,7 +79,7 @@ public class GitConstructionTest extends RepositoryTestCase {
assertEquals(1, git.branchList().call().size());
git = Git.wrap(bareRepo);
- assertEquals(2, git.branchList().setListMode(ListMode.ALL).call()
+ assertEquals(1, git.branchList().setListMode(ListMode.ALL).call()
.size());
try {
@@ -96,7 +96,7 @@ public class GitConstructionTest extends RepositoryTestCase {
assertEquals(1, git.branchList().call().size());
git = Git.open(bareRepo.getDirectory());
- assertEquals(2, git.branchList().setListMode(ListMode.ALL).call()
+ assertEquals(1, git.branchList().setListMode(ListMode.ALL).call()
.size());
git = Git.open(db.getWorkTree());