in maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/tag/HgTagCommand.java [59:126]
protected ScmResult executeTagCommand(
ScmProviderRepository scmProviderRepository,
ScmFileSet fileSet,
String tag,
ScmTagParameters scmTagParameters)
throws ScmException {
if (tag == null || tag.trim().isEmpty()) {
throw new ScmException("tag must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException(
"This provider doesn't support tagging subsets of a directory : " + fileSet.getFileList());
}
File workingDir = fileSet.getBasedir();
// build the command
String[] tagCmd = new String[] {
HgCommandConstants.TAG_CMD, HgCommandConstants.MESSAGE_OPTION, scmTagParameters.getMessage(), tag
};
// keep the command about in string form for reporting
StringBuilder cmd = joinCmd(tagCmd);
HgTagConsumer consumer = new HgTagConsumer();
ScmResult result = HgUtils.execute(consumer, workingDir, tagCmd);
HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
if (result.isSuccess()) {
// now push
// Push to parent branch if any
if (repository.isPushChanges()) {
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
String branchName = HgUtils.getCurrentBranchName(workingDir);
boolean differentOutgoingBranch = HgUtils.differentOutgoingBranchFound(workingDir, branchName);
String[] pushCmd = new String[] {
HgCommandConstants.PUSH_CMD,
differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName : null,
repository.getURI()
};
result = HgUtils.execute(new HgConsumer(), fileSet.getBasedir(), pushCmd);
}
}
} else {
throw new ScmException("Error while executing command " + cmd.toString());
}
// do an inventory to return the files tagged (all of them)
String[] listCmd = new String[] {HgCommandConstants.INVENTORY_CMD};
HgListConsumer listconsumer = new HgListConsumer();
result = HgUtils.execute(listconsumer, fileSet.getBasedir(), listCmd);
if (result.isSuccess()) {
List<ScmFile> files = listconsumer.getFiles();
List<ScmFile> fileList = new ArrayList<>();
for (ScmFile f : files) {
if (!f.getPath().endsWith(".hgtags")) {
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
}
return new TagScmResult(fileList, result);
} else {
throw new ScmException("Error while executing command " + cmd.toString());
}
}