1818 */
1919
2020/*
21- * Copyright (c) 2009, 2024 , Oracle and/or its affiliates. All rights reserved.
21+ * Copyright (c) 2009, 2025 , Oracle and/or its affiliates. All rights reserved.
2222 * Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
2323 */
2424package org .opengrok .indexer .history ;
@@ -483,8 +483,14 @@ void testBuildTagListInitial() throws Exception {
483483 }
484484
485485 /**
486- * Clone the original repository, add new tag, check that the extracted tags contain the pre-existing
487- * and new one.
486+ * 1. Clone the original repository
487+ * 2. create branch and add tag to the branch
488+ * 3. switch back to the original branch, add new tag
489+ * 4. check that the extracted tags contain the pre-existing and new one but not the non-default branch tag.
490+ * 5. add another tag
491+ * 6. switch to the non-default branch
492+ * 7. check that the extracted tags consist of the tags added to the default branch before the branch point
493+ * and also the tags added in that branch
488494 */
489495 @ Test
490496 void testBuildTagListOneMore () throws Exception {
@@ -494,9 +500,25 @@ void testBuildTagListOneMore() throws Exception {
494500 // Clone the internal repository because it will be modified.
495501 // This avoids interference with other tests in this class.
496502 runHgCommand (this .repositoryRoot , "clone" , this .repositoryRoot .toString (), repositoryRootPath .toString ());
503+
504+ // Branch the repo and add one changeset.
505+ runHgCommand (repositoryRoot , "unbundle" ,
506+ Paths .get (getClass ().getResource ("/history/hg-branch.bundle" ).toURI ()).toString ());
507+
508+ // Switch to the branch and add tag.
509+ final String myBranch = "mybranch" ;
510+ runHgCommand (repositoryRoot , "update" , myBranch );
511+ final String branchTagName = "branch_tag" ;
512+ runHgCommand (repositoryRoot , "tag" , branchTagName );
513+
514+ // Switch back to the default branch.
515+ runHgCommand (repositoryRoot , "update" , "default" );
516+
497517 MercurialRepository hgRepo = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
498518 assertNotNull (hgRepo );
499- // Using double space on purpose to test the parsing of tags.
519+ assertEquals ("default" , hgRepo .getBranch ());
520+
521+ // Add tag. Using double space on purpose to test the parsing of tags.
500522 final String newTagName = "foo bar" ;
501523 runHgCommand (repositoryRoot , "tag" , newTagName );
502524 hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
@@ -509,6 +531,24 @@ void testBuildTagListOneMore() throws Exception {
509531 assertEquals (List .of (7 , 9 ), tags .stream ().map (TagEntry ::getRevision ).collect (Collectors .toList ()));
510532 List <String > expectedTags = List .of ("start_of_novel" , newTagName );
511533 assertEquals (expectedTags , tags .stream ().map (TagEntry ::getTags ).collect (Collectors .toList ()));
534+
535+ // Add another tag to the default branch.
536+ runHgCommand (repositoryRoot , "tag" , "another_tag" );
537+
538+ // Switch back to the non-default branch, check tags.
539+ runHgCommand (repositoryRoot , "update" , myBranch );
540+ // The repository object has to be recreated to reflect the branch switch.
541+ hgRepo = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
542+ assertNotNull (hgRepo );
543+ assertEquals (myBranch , hgRepo .getBranch ());
544+ hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
545+ tags = hgRepo .getTagList ();
546+ assertNotNull (tags );
547+ assertEquals (3 , tags .size ());
548+ expectedTags = List .of ("start_of_novel" , newTagName , branchTagName );
549+ assertEquals (expectedTags , tags .stream ().map (TagEntry ::getTags ).collect (Collectors .toList ()));
550+
551+ // cleanup
512552 IOUtils .removeRecursive (repositoryRootPath );
513553 }
514554}
0 commit comments