Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -634,12 +634,12 @@ protected void buildTagList(File directory, CommandTimeoutType cmdType) {
ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("tags");
argv.add("--template");
argv.add("log");
argv.add("--rev=reverse(0::branch(" + this.getBranch() + ") and tag())");
// Use '|' as a revision separator rather than ':' to avoid collision with the commonly used
// separator within the revision string (which is not used in the 'hg tags' output but better
// separator within the revision string (which is not used in this output but better
// safe than sorry).
argv.add("{rev}|{tag}\\n");
argv.add("--template={latesttag % '{rev}|{tag}\\n'}");

Executor executor = new Executor(argv, directory,
RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -483,8 +483,14 @@ void testBuildTagListInitial() throws Exception {
}

/**
* Clone the original repository, add new tag, check that the extracted tags contain the pre-existing
* and new one.
* 1. Clone the original repository
* 2. create branch and add tag to the branch
* 3. switch back to the original branch, add new tag
* 4. check that the extracted tags contain the pre-existing and new one but not the non-default branch tag.
* 5. add another tag
* 6. switch to the non-default branch
* 7. check that the extracted tags consist of the tags added to the default branch before the branch point
* and also the tags added in that branch
*/
@Test
void testBuildTagListOneMore() throws Exception {
Expand All @@ -494,9 +500,25 @@ void testBuildTagListOneMore() throws Exception {
// Clone the internal repository because it will be modified.
// This avoids interference with other tests in this class.
runHgCommand(this.repositoryRoot, "clone", this.repositoryRoot.toString(), repositoryRootPath.toString());

// Branch the repo and add one changeset.
runHgCommand(repositoryRoot, "unbundle",
Paths.get(getClass().getResource("/history/hg-branch.bundle").toURI()).toString());

// Switch to the branch and add tag.
final String myBranch = "mybranch";
runHgCommand(repositoryRoot, "update", myBranch);
final String branchTagName = "branch_tag";
runHgCommand(repositoryRoot, "tag", branchTagName);

// Switch back to the default branch.
runHgCommand(repositoryRoot, "update", "default");

MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
assertNotNull(hgRepo);
// Using double space on purpose to test the parsing of tags.
assertEquals("default", hgRepo.getBranch());

// Add tag. Using double space on purpose to test the parsing of tags.
final String newTagName = "foo bar";
runHgCommand(repositoryRoot, "tag", newTagName);
hgRepo.buildTagList(new File(hgRepo.getDirectoryName()), CommandTimeoutType.INDEXER);
Expand All @@ -509,6 +531,24 @@ void testBuildTagListOneMore() throws Exception {
assertEquals(List.of(7, 9), tags.stream().map(TagEntry::getRevision).collect(Collectors.toList()));
List<String> expectedTags = List.of("start_of_novel", newTagName);
assertEquals(expectedTags, tags.stream().map(TagEntry::getTags).collect(Collectors.toList()));

// Add another tag to the default branch.
runHgCommand(repositoryRoot, "tag", "another_tag");

// Switch back to the non-default branch, check tags.
runHgCommand(repositoryRoot, "update", myBranch);
// The repository object has to be recreated to reflect the branch switch.
hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
assertNotNull(hgRepo);
assertEquals(myBranch, hgRepo.getBranch());
hgRepo.buildTagList(new File(hgRepo.getDirectoryName()), CommandTimeoutType.INDEXER);
tags = hgRepo.getTagList();
assertNotNull(tags);
assertEquals(3, tags.size());
expectedTags = List.of("start_of_novel", newTagName, branchTagName);
assertEquals(expectedTags, tags.stream().map(TagEntry::getTags).collect(Collectors.toList()));

// cleanup
IOUtils.removeRecursive(repositoryRootPath);
}
}
Loading