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( getLogger() ) {
public void doConsume( ScmFileStatus status, String trimmedLine )
{
}
};
ScmResult result = HgUtils.execute( branchConsumer, getLogger(), 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( getLogger() ), getLogger(), 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( getLogger() ), getLogger(), 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( getLogger() );
result = HgUtils.execute( listconsumer, getLogger(), 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<ScmFile>();
for ( Iterator<ScmFile> i = files.iterator(); i.hasNext(); )