Search in sources :

Example 6 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, ScmVersion startVersion, ScmVersion endVersion, String commandLine) throws Exception {
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
    Commandline cl = GitChangeLogCommand.createCommandLine(gitRepository, workingDirectory, branch, startDate, endDate, startVersion, endVersion);
    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 7 with GitScmProviderRepository

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

the class GitRemoteInfoCommand method executeRemoteInfoCommand.

@Override
public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository;
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    Commandline clLsRemote = createCommandLine(gitRepository);
    GitRemoteInfoConsumer consumer = new GitRemoteInfoConsumer(getLogger(), clLsRemote.toString());
    int exitCode = GitCommandLineUtils.execute(clLsRemote, consumer, stderr, getLogger());
    if (exitCode != 0) {
        throw new ScmException("unbale to execute ls-remote on " + gitRepository.getFetchUrl());
    }
    return consumer.getRemoteInfoScmResult();
}
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)

Example 8 with GitScmProviderRepository

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

the class GitTagCommand method executeTagCommand.

/**
 * {@inheritDoc}
 */
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
    if (tag == null || StringUtils.isEmpty(tag.trim())) {
        throw new ScmException("tag name must be specified");
    }
    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support tagging subsets of a directory");
    }
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
    try {
        FileUtils.fileWrite(messageFile.getAbsolutePath(), scmTagParameters.getMessage());
    } catch (IOException ex) {
        return new TagScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
    }
    try {
        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
        int exitCode;
        Commandline clTag = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile);
        exitCode = GitCommandLineUtils.execute(clTag, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new TagScmResult(clTag.toString(), "The git-tag command failed.", stderr.getOutput(), false);
        }
        if (repo.isPushChanges()) {
            // and now push the tag to the configured upstream repository
            Commandline clPush = createPushCommandLine(repository, fileSet, tag);
            exitCode = GitCommandLineUtils.execute(clPush, stdout, stderr, getLogger());
            if (exitCode != 0) {
                return new TagScmResult(clPush.toString(), "The git-push command failed.", stderr.getOutput(), false);
            }
        }
        // plus search for the tagged 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 CheckOutScmResult(clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false);
        }
        return new TagScmResult(clTag.toString(), listConsumer.getListedFiles());
    } finally {
        try {
            FileUtils.forceDelete(messageFile);
        } catch (IOException ex) {
        // ignore
        }
    }
}
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) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) IOException(java.io.IOException) TagScmResult(org.apache.maven.scm.command.tag.TagScmResult) File(java.io.File)

Example 9 with GitScmProviderRepository

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

the class GitTagCommandTest method testCommandLine.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
private void testCommandLine(String scmUrl, String tag, String commandLine) throws Exception {
    File workingDirectory = getTestFile("target/git-checkin-command-test");
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
    Commandline cl = GitTagCommand.createCommandLine(gitRepository, workingDirectory, tag, messageFile);
    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)

Example 10 with GitScmProviderRepository

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

the class GitAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    GitScmProviderRepository repository = (GitScmProviderRepository) repo;
    if (fileSet.getFileList().isEmpty()) {
        throw new ScmException("You must provide at least one file/directory to add");
    }
    AddScmResult result = executeAddFileSet(fileSet);
    if (result != null) {
        return result;
    }
    // SCM-709: statusCommand uses repositoryRoot instead of workingDirectory, adjust it with relativeRepositoryPath
    Commandline clRevparse = GitStatusCommand.createRevparseShowToplevelCommand(fileSet);
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    URI relativeRepositoryPath = null;
    int exitCode;
    exitCode = GitCommandLineUtils.execute(clRevparse, stdout, stderr, getLogger());
    if (exitCode != 0) {
        // git-status returns non-zero if nothing to do
        if (getLogger().isInfoEnabled()) {
            getLogger().info("Could not resolve toplevel");
        }
    } else {
        relativeRepositoryPath = GitStatusConsumer.resolveURI(stdout.getOutput().trim(), fileSet.getBasedir().toURI());
    }
    // git-add doesn't show single files, but only summary :/
    // so we must run git-status and consume the output
    // borrow a few things from the git-status command
    Commandline clStatus = GitStatusCommand.createCommandLine(repository, fileSet);
    GitStatusConsumer statusConsumer = new GitStatusConsumer(getLogger(), fileSet.getBasedir(), relativeRepositoryPath);
    stderr = new CommandLineUtils.StringStreamConsumer();
    exitCode = GitCommandLineUtils.execute(clStatus, statusConsumer, stderr, getLogger());
    if (exitCode != 0) {
        // git-status returns non-zero if nothing to do
        if (getLogger().isInfoEnabled()) {
            getLogger().info("nothing added to commit but untracked files present (use \"git add\" to track)");
        }
    }
    List<ScmFile> changedFiles = new ArrayList<ScmFile>();
    // rewrite all detected files to now have status 'checked_in'
    for (ScmFile scmfile : statusConsumer.getChangedFiles()) {
        // if a specific fileSet is given, we have to check if the file is really tracked
        for (File f : fileSet.getFileList()) {
            if (FilenameUtils.separatorsToUnix(f.getPath()).equals(scmfile.getPath())) {
                changedFiles.add(scmfile);
            }
        }
    }
    Commandline cl = createCommandLine(fileSet.getBasedir(), fileSet.getFileList());
    return new AddScmResult(cl.toString(), changedFiles);
}
Also used : ScmException(org.apache.maven.scm.ScmException) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ArrayList(java.util.ArrayList) URI(java.net.URI) ScmFile(org.apache.maven.scm.ScmFile) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) GitStatusConsumer(org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusConsumer) ScmFile(org.apache.maven.scm.ScmFile) 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