aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2015-07-23 14:14:46 -0400
committerMatthias Sohn <matthias.sohn@sap.com>2018-09-15 00:57:13 +0200
commit54a502f6c6f416dc570f023ffb48f05efd3af3ff (patch)
tree49b9eb121cc8d1ab20e2baef8daec7e46206ce72 /org.eclipse.jgit.test
parentcb4de02e5e7502705ef52264eb76d03a90c950d1 (diff)
downloadjgit-54a502f6c6f416dc570f023ffb48f05efd3af3ff.tar.gz
jgit-54a502f6c6f416dc570f023ffb48f05efd3af3ff.zip
Fix fetch refspecs when not cloning all branches
When not all branches are cloned, the fetch refspec for the remote should not be "+refs/heads/*:refs/remotes/origin/*": that would fetch all branches on the very next fetch, thus making a clone with only a subset of the branches rather pointless. Instead, produce refspecs for the cloned branches only. Canonical git also does this for its --single-branch case; it doesn't have an option to clone only a subset of the branches (only one or all). Bug: 466858 Change-Id: Ie871880f757663437efac1e8b3313094f9e629b3 Also-by: Julian Enoch <julian.enoch@ericsson.com> Signed-off-by: Julian Enoch <julian.enoch@ericsson.com> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: David Pursehouse <david.pursehouse@gmail.com> 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.java27
1 files changed, 22 insertions, 5 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 0d7009dca4..0ad067f6a7 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
@@ -370,8 +370,7 @@ public class CloneCommandTest extends RepositoryTestCase {
}
@Test
- public void testCloneRepositoryOnlyOneBranch() throws IOException,
- JGitInternalException, GitAPIException {
+ public void testCloneRepositoryOnlyOneBranch() throws Exception {
File directory = createTempDirectory("testCloneRepositoryWithBranch");
CloneCommand command = Git.cloneRepository();
command.setBranch("refs/heads/master");
@@ -385,22 +384,40 @@ public class CloneCommandTest extends RepositoryTestCase {
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
assertEquals("refs/remotes/origin/master", allRefNames(git2
.branchList().setListMode(ListMode.REMOTE).call()));
+ 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/master:refs/remotes/origin/master"),
+ specs.get(0));
+ }
+ @Test
+ public void testBareCloneRepositoryOnlyOneBranch() throws Exception {
// Same thing, but now test with bare repo
- directory = createTempDirectory("testCloneRepositoryWithBranch_bare");
- command = Git.cloneRepository();
+ File directory = createTempDirectory(
+ "testCloneRepositoryWithBranch_bare");
+ CloneCommand command = Git.cloneRepository();
command.setBranch("refs/heads/master");
command.setBranchesToClone(Collections
.singletonList("refs/heads/master"));
command.setDirectory(directory);
command.setURI(fileUri());
command.setBare(true);
- git2 = command.call();
+ Git git2 = command.call();
addRepoToClose(git2.getRepository());
assertNotNull(git2);
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
assertEquals("refs/heads/master", allRefNames(git2.branchList()
.setListMode(ListMode.ALL).call()));
+ 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/master:refs/heads/master"),
+ specs.get(0));
}
public static String allRefNames(List<Ref> refs) {