Search in sources :

Example 1 with HgStatusCommand

use of org.apache.maven.scm.provider.hg.command.status.HgStatusCommand in project maven-scm by apache.

the class HgCheckInCommand method executeCheckInCommand.

/**
 * {@inheritDoc}
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion tag) throws ScmException {
    if (tag != null && !StringUtils.isEmpty(tag.getName())) {
        throw new ScmException("This provider can't handle tags for this operation");
    }
    File workingDir = fileSet.getBasedir();
    String branchName = HgUtils.getCurrentBranchName(getLogger(), workingDir);
    boolean differentOutgoingBranch = repo.isPushChanges() ? HgUtils.differentOutgoingBranchFound(getLogger(), workingDir, branchName) : false;
    // Get files that will be committed (if not specified in fileSet)
    List<ScmFile> commitedFiles = new ArrayList<ScmFile>();
    List<File> files = fileSet.getFileList();
    if (files.isEmpty()) {
        // Either commit all changes
        HgStatusCommand statusCmd = new HgStatusCommand();
        statusCmd.setLogger(getLogger());
        StatusScmResult status = statusCmd.executeStatusCommand(repo, fileSet);
        List<ScmFile> statusFiles = status.getChangedFiles();
        for (ScmFile file : statusFiles) {
            if (file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED || file.getStatus() == ScmFileStatus.MODIFIED) {
                commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
            }
        }
    } else {
        // Or commit spesific files
        for (File file : files) {
            commitedFiles.add(new ScmFile(file.getPath(), ScmFileStatus.CHECKED_IN));
        }
    }
    // Commit to local branch
    String[] commitCmd = new String[] { HgCommandConstants.COMMIT_CMD, HgCommandConstants.MESSAGE_OPTION, message };
    commitCmd = HgUtils.expandCommandLine(commitCmd, fileSet);
    ScmResult result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), commitCmd);
    // Push to parent branch if any
    HgScmProviderRepository repository = (HgScmProviderRepository) repo;
    if (repo.isPushChanges()) {
        if (!repository.getURI().equals(fileSet.getBasedir().getAbsolutePath())) {
            String[] pushCmd = new String[] { HgCommandConstants.PUSH_CMD, differentOutgoingBranch ? HgCommandConstants.REVISION_OPTION + branchName : null, repository.getURI() };
            result = HgUtils.execute(new HgConsumer(getLogger()), getLogger(), fileSet.getBasedir(), pushCmd);
        }
        return new CheckInScmResult(commitedFiles, result);
    }
    return new CheckInScmResult(commitedFiles, result);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) ScmException(org.apache.maven.scm.ScmException) ScmResult(org.apache.maven.scm.ScmResult) StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) HgConsumer(org.apache.maven.scm.provider.hg.command.HgConsumer) ArrayList(java.util.ArrayList) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) ScmFile(org.apache.maven.scm.ScmFile) ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) HgStatusCommand(org.apache.maven.scm.provider.hg.command.status.HgStatusCommand) HgScmProviderRepository(org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository)

Example 2 with HgStatusCommand

use of org.apache.maven.scm.provider.hg.command.status.HgStatusCommand in project maven-scm by apache.

the class HgScmProvider method status.

/**
 * {@inheritDoc}
 */
public StatusScmResult status(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    HgStatusCommand command = new HgStatusCommand();
    command.setLogger(getLogger());
    return (StatusScmResult) command.execute(repository, fileSet, parameters);
}
Also used : StatusScmResult(org.apache.maven.scm.command.status.StatusScmResult) HgStatusCommand(org.apache.maven.scm.provider.hg.command.status.HgStatusCommand)

Aggregations

StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)2 HgStatusCommand (org.apache.maven.scm.provider.hg.command.status.HgStatusCommand)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ScmException (org.apache.maven.scm.ScmException)1 ScmFile (org.apache.maven.scm.ScmFile)1 ScmResult (org.apache.maven.scm.ScmResult)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 HgConsumer (org.apache.maven.scm.provider.hg.command.HgConsumer)1 HgScmProviderRepository (org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository)1