summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-04-09 20:51:15 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-04-12 13:56:52 +0200
commit060dcf1ccab6c43e4d5cc19524fafa3e82e351e0 (patch)
tree5dbbcf3c97aeb5312b5bbf3467117bc04a233570 /org.eclipse.jgit.test/tst/org/eclipse
parent5cc9ecde8f9de1b48f90a59160a71cf108a984b2 (diff)
downloadjgit-060dcf1ccab6c43e4d5cc19524fafa3e82e351e0.tar.gz
jgit-060dcf1ccab6c43e4d5cc19524fafa3e82e351e0.zip
ListTagCommand: implement git tag --contains
Change-Id: I07e57ba098eace9656393837fad4cb3590f31b22
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
index 99034174ba..c3f72135d6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
@@ -17,13 +17,16 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidTagNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
@@ -286,4 +289,45 @@ public class TagCommandTest extends RepositoryTestCase {
}
}
+ @Test
+ public void testListTagsContainingCommit() throws Exception {
+ /* c3
+ * |
+ * v2 - c2 b2 - v1
+ * | |
+ * c1 b1
+ * \ /
+ * a
+ */
+ try (TestRepository<Repository> r = new TestRepository<>(
+ db)) {
+ Git git = Git.wrap(db);
+ RevCommit a = r.commit().create();
+ RevCommit b1 = r.commit(a);
+ RevCommit b2 = r.commit(b1);
+ RevCommit c1 = r.commit(a);
+ RevCommit c2 = r.commit(c1);
+ RevCommit c3 = r.commit(c2);
+ r.update("refs/tags/v1", r.tag("v1", b2));
+ r.update("refs/tags/v2", r.tag("v1.1", c2));
+ List<Ref> res = git.tagList().setContains(a).call();
+ assertEquals(2, res.size());
+ assertTrue(res.stream().map(Ref::getName)
+ .collect(Collectors.toSet()).containsAll(
+ Arrays.asList("refs/tags/v1", "refs/tags/v2")));
+
+ res = git.tagList().setContains(b1).call();
+ assertEquals(1, res.size());
+ assertTrue(res.stream().map(Ref::getName)
+ .collect(Collectors.toSet()).contains("refs/tags/v1"));
+
+ res = git.tagList().setContains(c1).call();
+ assertEquals(1, res.size());
+ assertTrue(res.stream().map(Ref::getName)
+ .collect(Collectors.toSet()).contains("refs/tags/v2"));
+
+ res = git.tagList().setContains(c3).call();
+ assertEquals(0, res.size());
+ }
+ }
}