Search in sources :

Example 1 with GitDiffRawConsumer

use of org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffRawConsumer in project maven-scm by apache.

the class GitUpdateCommand method executeUpdateCommand.

/**
 * {@inheritDoc}
 */
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion scmVersion) throws ScmException {
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    if (GitScmProviderRepository.PROTOCOL_FILE.equals(repository.getFetchInfo().getProtocol()) && repository.getFetchInfo().getPath().indexOf(fileSet.getBasedir().getPath()) >= 0) {
        throw new ScmException("remote repository must not be the working directory");
    }
    int exitCode;
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    // fir we need to get the current reversion
    Commandline clRev = createLatestRevisionCommandLine(repository, fileSet.getBasedir(), scmVersion);
    GitLatestRevisionCommandConsumer consumerRev = new GitLatestRevisionCommandConsumer(getLogger());
    exitCode = GitCommandLineUtils.execute(clRev, consumerRev, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(clRev.toString(), "The git-log command failed.", stderr.getOutput(), false);
    }
    String origSha1 = consumerRev.getLatestRevision();
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), scmVersion);
    exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(cl.toString(), "The git-pull command failed.", stderr.getOutput(), false);
    }
    // we also need to log exactly what has been updated
    GitDiffRawConsumer diffRawConsumer = new GitDiffRawConsumer(getLogger());
    Commandline clDiffRaw = GitDiffCommand.createDiffRawCommandLine(fileSet.getBasedir(), origSha1);
    exitCode = GitCommandLineUtils.execute(clDiffRaw, diffRawConsumer, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(clDiffRaw.toString(), "The git-diff --raw command failed.", stderr.getOutput(), false);
    }
    // now let's get the latest version
    consumerRev = new GitLatestRevisionCommandConsumer(getLogger());
    exitCode = GitCommandLineUtils.execute(clRev, consumerRev, stderr, getLogger());
    if (exitCode != 0) {
        return new UpdateScmResult(clRev.toString(), "The git-log command failed.", stderr.getOutput(), false);
    }
    String latestRevision = consumerRev.getLatestRevision();
    return new UpdateScmResultWithRevision(cl.toString(), diffRawConsumer.getChangedFiles(), latestRevision);
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) UpdateScmResultWithRevision(org.apache.maven.scm.command.update.UpdateScmResultWithRevision) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) UpdateScmResult(org.apache.maven.scm.command.update.UpdateScmResult) GitDiffRawConsumer(org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffRawConsumer)

Aggregations

ScmException (org.apache.maven.scm.ScmException)1 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)1 UpdateScmResultWithRevision (org.apache.maven.scm.command.update.UpdateScmResultWithRevision)1 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)1 GitDiffRawConsumer (org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffRawConsumer)1 GitScmProviderRepository (org.apache.maven.scm.provider.git.repository.GitScmProviderRepository)1 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)1 Commandline (org.codehaus.plexus.util.cli.Commandline)1