@@ -499,8 +499,10 @@ void testBuildTagListOneMore() throws Exception {
499499 // Branch the repo and add one changeset.
500500 runHgCommand (repositoryRoot , "unbundle" ,
501501 Paths .get (getClass ().getResource ("/history/hg-branch.bundle" ).toURI ()).toString ());
502+
502503 // Switch to the branch and add tag.
503- runHgCommand (repositoryRoot , "update" , "mybranch" );
504+ final String myBranch = "mybranch" ;
505+ runHgCommand (repositoryRoot , "update" , myBranch );
504506 final String branchTagName = "branch_tag" ;
505507 runHgCommand (repositoryRoot , "tag" , branchTagName );
506508
@@ -509,7 +511,8 @@ void testBuildTagListOneMore() throws Exception {
509511
510512 MercurialRepository hgRepo = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
511513 assertNotNull (hgRepo );
512- // Using double space on purpose to test the parsing of tags.
514+
515+ // Add tag. Using double space on purpose to test the parsing of tags.
513516 final String newTagName = "foo bar" ;
514517 runHgCommand (repositoryRoot , "tag" , newTagName );
515518 hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
@@ -522,6 +525,23 @@ void testBuildTagListOneMore() throws Exception {
522525 assertEquals (List .of (7 , 9 ), tags .stream ().map (TagEntry ::getRevision ).collect (Collectors .toList ()));
523526 List <String > expectedTags = List .of ("start_of_novel" , newTagName );
524527 assertEquals (expectedTags , tags .stream ().map (TagEntry ::getTags ).collect (Collectors .toList ()));
528+
529+ // Add another tag to the default branch.
530+ runHgCommand (repositoryRoot , "tag" , "another_tag" );
531+
532+ // Switch back to the non-default branch, check tags.
533+ runHgCommand (repositoryRoot , "update" , myBranch );
534+ // The repository object has to be recreated to reflect the branch switch.
535+ hgRepo = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
536+ assertNotNull (hgRepo );
537+ hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
538+ tags = hgRepo .getTagList ();
539+ assertNotNull (tags );
540+ assertEquals (3 , tags .size ());
541+ expectedTags = List .of ("start_of_novel" , newTagName , branchTagName );
542+ assertEquals (expectedTags , tags .stream ().map (TagEntry ::getTags ).collect (Collectors .toList ()));
543+
544+ // cleanup
525545 IOUtils .removeRecursive (repositoryRootPath );
526546 }
527547}
0 commit comments