|
36 | 36 | import java.util.HashSet;
|
37 | 37 | import java.util.List;
|
38 | 38 | import java.util.Set;
|
| 39 | +import java.util.TreeSet; |
39 | 40 |
|
40 | 41 | import org.eclipse.jgit.api.Git;
|
| 42 | +import org.eclipse.jgit.lib.ObjectId; |
41 | 43 | import org.eclipse.jgit.lib.Ref;
|
| 44 | +import org.eclipse.jgit.revwalk.RevCommit; |
| 45 | +import org.eclipse.jgit.revwalk.RevWalk; |
42 | 46 | import org.eclipse.jgit.transport.URIish;
|
43 | 47 | import org.junit.After;
|
44 | 48 | import org.junit.AfterClass;
|
@@ -623,6 +627,46 @@ public void testBuildTagList() throws Exception {
|
623 | 627 | gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER);
|
624 | 628 | assertEquals(0, gitrepo.getTagList().size());
|
625 | 629 |
|
626 |
| - // TODO: add some tags (using JGit), rebuild tag list |
| 630 | + try (Git git = Git.open(root)) { |
| 631 | + // Tag the HEAD first. |
| 632 | + Ref ref = git.tag().setName("one").call(); |
| 633 | + assertNotNull(ref); |
| 634 | + gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER); |
| 635 | + Set<TagEntry> tags = gitrepo.getTagList(); |
| 636 | + assertEquals(1, tags.size()); |
| 637 | + Date date = new Date((long) (1485438707) * 1000); |
| 638 | + TagEntry tagEntry = new GitTagEntry("84599b3cccb3eeb5aa9aec64771678d6526bcecb", date, "one"); |
| 639 | + assertEquals(tagEntry, tags.toArray()[0]); |
| 640 | + |
| 641 | + // Tag again so that single changeset has multiple tags. |
| 642 | + ref = git.tag().setName("two").call(); |
| 643 | + assertNotNull(ref); |
| 644 | + gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER); |
| 645 | + tags = gitrepo.getTagList(); |
| 646 | + assertEquals(1, tags.size()); |
| 647 | + Set<TagEntry> expectedTags = new TreeSet<>(); |
| 648 | + date = new Date((long) (1485438707) * 1000); |
| 649 | + tagEntry = new GitTagEntry("84599b3cccb3eeb5aa9aec64771678d6526bcecb", date, "one, two"); |
| 650 | + expectedTags.add(tagEntry); |
| 651 | + assertEquals(expectedTags, tags); |
| 652 | + |
| 653 | + // Tag specific changeset (not HEAD) and recheck. |
| 654 | + org.eclipse.jgit.lib.Repository repo = git.getRepository(); |
| 655 | + RevCommit commit; |
| 656 | + ObjectId objectId = repo.resolve("b6413947a5"); |
| 657 | + try (RevWalk walk = new RevWalk(repo)) { |
| 658 | + commit = walk.parseCommit(objectId); |
| 659 | + } |
| 660 | + assertNotNull(commit); |
| 661 | + ref = git.tag().setName("three").setObjectId(commit).call(); |
| 662 | + assertNotNull(ref); |
| 663 | + gitrepo.buildTagList(new File(gitrepo.getDirectoryName()), CommandTimeoutType.INDEXER); |
| 664 | + tags = gitrepo.getTagList(); |
| 665 | + assertEquals(2, tags.size()); |
| 666 | + date = new Date((long) (1485263264) * 1000); |
| 667 | + tagEntry = new GitTagEntry("b6413947a59f481ddc0a05e0d181731233557f6e", date, "three"); |
| 668 | + expectedTags.add(tagEntry); |
| 669 | + assertEquals(expectedTags, tags); |
| 670 | + } |
627 | 671 | }
|
628 | 672 | }
|
0 commit comments