in maven-scm-providers/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/branch/HgBranchCommand.java [60:139]
protected ScmResult executeBranchCommand(
ScmProviderRepository scmProviderRepository,
ScmFileSet fileSet,
String branch,
ScmBranchParameters scmBranchParameters)
throws ScmException {
if (StringUtils.isBlank(branch)) {
throw new ScmException("branch must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support branchging subsets of a directory");
}
File workingDir = fileSet.getBasedir();
// build the command
String[] branchCmd = new String[] {HgCommandConstants.BRANCH_CMD, branch};
// keep the command about in string form for reporting
HgConsumer branchConsumer = new HgConsumer() {
public void doConsume(ScmFileStatus status, String trimmedLine) {
// noop
}
};
ScmResult result = HgUtils.execute(branchConsumer, workingDir, branchCmd);
HgScmProviderRepository repository = (HgScmProviderRepository) scmProviderRepository;
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(branchCmd));
}
// First commit.
String[] commitCmd = new String[] {
HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, scmBranchParameters.getMessage()
};
result = HgUtils.execute(new HgConsumer(), workingDir, commitCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(commitCmd));
}
// now push, if we should.
if (repository.isPushChanges()) {
if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
String[] pushCmd = new String[] {
HgCommandConstants.PUSH_CMD, HgCommandConstants.NEW_BRANCH_OPTION, repository.getURI()
};
result = HgUtils.execute(new HgConsumer(), fileSet.getBasedir(), pushCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(pushCmd));
}
}
}
// do an inventory to return the files branched (all of them)
String[] listCmd = new String[] {HgCommandConstants.INVENTORY_CMD};
HgListConsumer listconsumer = new HgListConsumer();
result = HgUtils.execute(listconsumer, fileSet.getBasedir(), listCmd);
if (!result.isSuccess()) {
throw new ScmException("Error while executing command " + joinCmd(listCmd));
}
List<ScmFile> files = listconsumer.getFiles();
List<ScmFile> fileList = new ArrayList<>();
for (ScmFile f : files) {
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new BranchScmResult(fileList, result);
}