@@ -639,16 +639,42 @@ public void testRenamedSingleHistory() throws Exception {
639
639
}
640
640
641
641
@ Test
642
- public void testBuildTagList () throws Exception {
642
+ public void testBuildTagListEmpty () throws Exception {
643
643
File root = new File (repository .getSourceRoot (), "git" );
644
- GitRepository gitrepo
645
- = (GitRepository ) RepositoryFactory .getRepository (root );
646
- gitrepo .buildTagList (new File (gitrepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
647
- assertEquals (0 , gitrepo .getTagList ().size ());
644
+ // Clone under source root to avoid problems with prohibited symlinks.
645
+ File localPath = new File (repository .getSourceRoot (), "testBuildTagListEmpty" );
646
+ String cloneUrl = root .toURI ().toString ();
647
+ try (Git gitClone = Git .cloneRepository ()
648
+ .setURI (cloneUrl )
649
+ .setDirectory (localPath )
650
+ .call ()) {
651
+
652
+ File cloneRoot = gitClone .getRepository ().getWorkTree ();
653
+
654
+ GitRepository gitrepo = (GitRepository ) RepositoryFactory .getRepository (cloneRoot );
655
+ gitrepo .buildTagList (new File (gitrepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
656
+ assertEquals (0 , gitrepo .getTagList ().size ());
657
+
658
+ FileUtilities .removeDirs (cloneRoot );
659
+ }
660
+ }
661
+
662
+ @ Test
663
+ public void testBuildTagListMultipleTags () throws Exception {
664
+ File root = new File (repository .getSourceRoot (), "git" );
665
+ // Clone under source root to avoid problems with prohibited symlinks.
666
+ File localPath = new File (repository .getSourceRoot (), "testBuildTagListMultipleTags" );
667
+ String cloneUrl = root .toURI ().toString ();
668
+ try (Git gitClone = Git .cloneRepository ()
669
+ .setURI (cloneUrl )
670
+ .setDirectory (localPath )
671
+ .call ()) {
672
+
673
+ File cloneRoot = gitClone .getRepository ().getWorkTree ();
674
+ GitRepository gitrepo = (GitRepository ) RepositoryFactory .getRepository (cloneRoot );
648
675
649
- try (Git git = Git .open (root )) {
650
676
// Tag the HEAD first.
651
- Ref ref = git .tag ().setName ("one" ).call ();
677
+ Ref ref = gitClone .tag ().setName ("one" ).call ();
652
678
assertNotNull (ref );
653
679
gitrepo .buildTagList (new File (gitrepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
654
680
Set <TagEntry > tags = gitrepo .getTagList ();
@@ -658,7 +684,7 @@ public void testBuildTagList() throws Exception {
658
684
assertEquals (tagEntry , tags .toArray ()[0 ]);
659
685
660
686
// Tag again so that single changeset has multiple tags.
661
- ref = git .tag ().setName ("two" ).call ();
687
+ ref = gitClone .tag ().setName ("two" ).call ();
662
688
assertNotNull (ref );
663
689
gitrepo .buildTagList (new File (gitrepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
664
690
tags = gitrepo .getTagList ();
@@ -669,23 +695,44 @@ public void testBuildTagList() throws Exception {
669
695
expectedTags .add (tagEntry );
670
696
assertEquals (expectedTags , tags );
671
697
698
+ FileUtilities .removeDirs (cloneRoot );
699
+ }
700
+ }
701
+
702
+ @ Test
703
+ public void testBuildTagListNotHead () throws Exception {
704
+ File root = new File (repository .getSourceRoot (), "git" );
705
+ // Clone under source root to avoid problems with prohibited symlinks.
706
+ File localPath = new File (repository .getSourceRoot (), "testBuildTagListNotHead" );
707
+ String cloneUrl = root .toURI ().toString ();
708
+ try (Git gitClone = Git .cloneRepository ()
709
+ .setURI (cloneUrl )
710
+ .setDirectory (localPath )
711
+ .call ()) {
712
+
713
+ File cloneRoot = gitClone .getRepository ().getWorkTree ();
714
+ GitRepository gitrepo = (GitRepository ) RepositoryFactory .getRepository (cloneRoot );
715
+
672
716
// Tag specific changeset (not HEAD) and recheck.
673
- org .eclipse .jgit .lib .Repository repo = git .getRepository ();
717
+ org .eclipse .jgit .lib .Repository repo = gitClone .getRepository ();
674
718
RevCommit commit ;
675
719
ObjectId objectId = repo .resolve ("b6413947a5" );
676
720
try (RevWalk walk = new RevWalk (repo )) {
677
721
commit = walk .parseCommit (objectId );
678
722
}
679
723
assertNotNull (commit );
680
- ref = git .tag ().setName ("three" ).setObjectId (commit ).call ();
724
+ Ref ref = gitClone .tag ().setName ("three" ).setObjectId (commit ).call ();
681
725
assertNotNull (ref );
682
726
gitrepo .buildTagList (new File (gitrepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
683
- tags = gitrepo .getTagList ();
684
- assertEquals (2 , tags .size ());
685
- date = new Date ((long ) (1485263264 ) * 1000 );
686
- tagEntry = new GitTagEntry ("b6413947a59f481ddc0a05e0d181731233557f6e" , date , "three" );
727
+ Set <TagEntry > tags = gitrepo .getTagList ();
728
+ assertEquals (1 , tags .size ());
729
+ Date date = new Date ((long ) (1485263264 ) * 1000 );
730
+ Set <TagEntry > expectedTags = new TreeSet <>();
731
+ TagEntry tagEntry = new GitTagEntry ("b6413947a59f481ddc0a05e0d181731233557f6e" , date , "three" );
687
732
expectedTags .add (tagEntry );
688
733
assertEquals (expectedTags , tags );
734
+
735
+ FileUtilities .removeDirs (cloneRoot );
689
736
}
690
737
}
691
738
}
0 commit comments