summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2018-12-11 00:47:13 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-01-27 22:56:06 +0100
commite7b4d108e19913362e92b17fa6ad5b7c9afba23f (patch)
tree9861b1b3cee48e98ed6339cf11e7ee915bf702b5 /org.eclipse.jgit.test
parent0d33af9ff5604b1913e91606bcbc63f2fd36197d (diff)
downloadjgit-e7b4d108e19913362e92b17fa6ad5b7c9afba23f.tar.gz
jgit-e7b4d108e19913362e92b17fa6ad5b7c9afba23f.zip
Enable cloning only specific tags
Single-branch-clone should be able to clone a single tag. Enhance CloneCommand to accept also full refs of tags in setBranchesToClone(). Make sure we also include fetch ref specs for the fetch command for tags. This mimics the behavior of native git's single-branch clone: git clone --branch <tag> --single-branch <URI> Bug: 542611 Change-Id: I285cf043751d9b0ba71258ee8214c0e5d1191428 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java26
1 files changed, 26 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 6b5fe502b7..1523b49ecc 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
@@ -424,6 +424,32 @@ public class CloneCommandTest extends RepositoryTestCase {
specs.get(0));
}
+ @Test
+ public void testCloneRepositoryOnlyOneTag() throws Exception {
+ File directory = createTempDirectory("testCloneRepositoryWithBranch");
+ CloneCommand command = Git.cloneRepository();
+ command.setBranch("tag-initial");
+ command.setBranchesToClone(
+ Collections.singletonList("refs/tags/tag-initial"));
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+ assertNotNull(git2);
+ assertNull(git2.getRepository().resolve("tag-for-blob"));
+ assertNull(git2.getRepository().resolve("refs/heads/master"));
+ assertNotNull(git2.getRepository().resolve("tag-initial"));
+ ObjectId taggedCommit = db.resolve("tag-initial^{commit}");
+ assertEquals(taggedCommit.name(), git2.getRepository().getFullBranch());
+ RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(),
+ Constants.DEFAULT_REMOTE_NAME);
+ List<RefSpec> specs = cfg.getFetchRefSpecs();
+ assertEquals(1, specs.size());
+ assertEquals(
+ new RefSpec("+refs/tags/tag-initial:refs/tags/tag-initial"),
+ specs.get(0));
+ }
+
public static String allRefNames(List<Ref> refs) {
StringBuilder sb = new StringBuilder();
for (Ref f : refs) {