Search in sources :

Example 16 with GitScmProviderRepository

use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository 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)

Example 17 with GitScmProviderRepository

use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.

the class GitChangeLogCommandTest method testCommandLine.

private void testCommandLine(String scmUrl, ScmBranch branch, Date startDate, Date endDate, Integer limit, String commandLine) throws Exception {
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
    Commandline cl = GitChangeLogCommand.createCommandLine(gitRepository, workingDirectory, branch, startDate, endDate, null, null, limit);
    assertCommandLine(commandLine, workingDirectory, cl);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline)

Example 18 with GitScmProviderRepository

use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.

the class GitBranchCommand method executeBranchCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch, String message) throws ScmException {
    if (branch == null || StringUtils.isEmpty(branch.trim())) {
        throw new ScmException("branch name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branching subsets of a directory");
    }
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    Commandline cl = createCommandLine(repository, fileSet.getBasedir(), branch);
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    if (exitCode != 0) {
        return new BranchScmResult(cl.toString(), "The git-branch command failed.", stderr.getOutput(), false);
    }
    if (repo.isPushChanges()) {
        // and now push the branch to the upstream repository
        Commandline clPush = createPushCommandLine(repository, fileSet, branch);
        exitCode = GitCommandLineUtils.execute(clPush, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new BranchScmResult(clPush.toString(), "The git-push command failed.", stderr.getOutput(), false);
        }
    }
    // as last action we search for the branched files
    GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.TAGGED);
    Commandline clList = GitListCommand.createCommandLine(repository, fileSet.getBasedir());
    exitCode = GitCommandLineUtils.execute(clList, listConsumer, stderr, getLogger());
    if (exitCode != 0) {
        return new BranchScmResult(clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
    }
    return new BranchScmResult(cl.toString(), listConsumer.getListedFiles());
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) GitListConsumer(org.apache.maven.scm.provider.git.gitexe.command.list.GitListConsumer) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult)

Example 19 with GitScmProviderRepository

use of org.apache.maven.scm.provider.git.repository.GitScmProviderRepository in project maven-scm by apache.

the class GitUpdateCommandTest method testLatestRevisionCommandLine.

private void testLatestRevisionCommandLine(String scmUrl, ScmBranch branch, String commandLine) throws Exception {
    File workingDirectory = getTestFile("target/git-update-command-test");
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
    Commandline cl = GitUpdateCommand.createLatestRevisionCommandLine(gitRepository, workingDirectory, branch);
    assertCommandLine(commandLine, workingDirectory, cl);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) File(java.io.File)

Aggregations

GitScmProviderRepository (org.apache.maven.scm.provider.git.repository.GitScmProviderRepository)19 Commandline (org.codehaus.plexus.util.cli.Commandline)16 File (java.io.File)9 ScmException (org.apache.maven.scm.ScmException)9 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)8 ScmRepository (org.apache.maven.scm.repository.ScmRepository)8 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)8 ArrayList (java.util.ArrayList)3 ScmFile (org.apache.maven.scm.ScmFile)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 RemoteInfoScmResult (org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult)3 GitListConsumer (org.apache.maven.scm.provider.git.gitexe.command.list.GitListConsumer)3 IOException (java.io.IOException)2 URI (java.net.URI)2 GitStatusConsumer (org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusConsumer)2 Git (org.eclipse.jgit.api.Git)2 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)2 HashMap (java.util.HashMap)1 ScmFileSet (org.apache.maven.scm.ScmFileSet)1 ScmRevision (org.apache.maven.scm.ScmRevision)1