18
18
*/
19
19
20
20
/*
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.
22
22
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
23
23
*/
24
24
package org .opengrok .indexer .history ;
@@ -483,8 +483,14 @@ void testBuildTagListInitial() throws Exception {
483
483
}
484
484
485
485
/**
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
488
494
*/
489
495
@ Test
490
496
void testBuildTagListOneMore () throws Exception {
@@ -494,9 +500,25 @@ void testBuildTagListOneMore() throws Exception {
494
500
// Clone the internal repository because it will be modified.
495
501
// This avoids interference with other tests in this class.
496
502
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
+
497
517
MercurialRepository hgRepo = (MercurialRepository ) RepositoryFactory .getRepository (repositoryRoot );
498
518
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.
500
522
final String newTagName = "foo bar" ;
501
523
runHgCommand (repositoryRoot , "tag" , newTagName );
502
524
hgRepo .buildTagList (new File (hgRepo .getDirectoryName ()), CommandTimeoutType .INDEXER );
@@ -509,6 +531,24 @@ void testBuildTagListOneMore() throws Exception {
509
531
assertEquals (List .of (7 , 9 ), tags .stream ().map (TagEntry ::getRevision ).collect (Collectors .toList ()));
510
532
List <String > expectedTags = List .of ("start_of_novel" , newTagName );
511
533
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
512
552
IOUtils .removeRecursive (repositoryRootPath );
513
553
}
514
554
}
0 commit comments