Search in sources :

Example 11 with GitScmProviderRepository

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

the class GitCheckInCommandTest method testCommandLine.

private void testCommandLine(String scmUrl, String commandLine) throws Exception {
    File workingDirectory = getTestFile("target/git-checkin-command-test");
    ScmRepository repository = getScmManager().makeScmRepository(scmUrl);
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
    Commandline cl = GitCheckInCommand.createCommitCommandLine(gitRepository, new ScmFileSet(workingDirectory), messageFile);
    assertCommandLine(commandLine, workingDirectory, cl);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository) Commandline(org.codehaus.plexus.util.cli.Commandline) File(java.io.File)

Example 12 with GitScmProviderRepository

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

the class GitCheckOutCommandTest method testCommandLine.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
private void testCommandLine(ScmManager scmManager, String scmUrl, String revision, String commandLine) throws Exception {
    ScmRepository repository = scmManager.makeScmRepository(scmUrl);
    GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
    Commandline cl = GitCheckOutCommand.createCommandLine(gitRepository, workingDirectory, new ScmRevision(revision));
    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) ScmRevision(org.apache.maven.scm.ScmRevision)

Example 13 with GitScmProviderRepository

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

the class GitUpdateCommandTest method testCommandLine.

// ----------------------------------------------------------------------
// private helper functions
// ----------------------------------------------------------------------
private void testCommandLine(String scmUrl, ScmVersion 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.createCommandLine(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)

Example 14 with GitScmProviderRepository

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

the class AbstractGitScmProvider method parseScmUrl.

// ----------------------------------------------------------------------
// 
// ----------------------------------------------------------------------
/**
 * The git-submodule(1) command is available since Git 1.5.3, so modules will
 * be activated in a later stage
 */
private ScmUrlParserResult parseScmUrl(String scmSpecificUrl, char delimiter) throws ScmException {
    ScmUrlParserResult result = new ScmUrlParserResult();
    result.repository = new GitScmProviderRepository(scmSpecificUrl);
    return result;
}
Also used : GitScmProviderRepository(org.apache.maven.scm.provider.git.repository.GitScmProviderRepository)

Example 15 with GitScmProviderRepository

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

the class GitCheckOutCommand method executeCheckOutCommand.

/**
 * For git, the given repository is a remote one.
 * We have to clone it first if the working directory does not contain a git repo yet,
 * otherwise we have to git-pull it.
 * <p/>
 * TODO We currently assume a '.git' directory, so this does not work for --bare repos
 * {@inheritDoc}
 */
protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive, boolean shallow) 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();
    String lastCommandLine = "git-nothing-to-do";
    if (!fileSet.getBasedir().exists() || !(new File(fileSet.getBasedir(), ".git").exists())) {
        if (fileSet.getBasedir().exists()) {
            // git refuses to clone otherwise
            fileSet.getBasedir().delete();
        }
        // no git repo seems to exist, let's clone the original repo
        Commandline clClone = createCloneCommand(repository, fileSet.getBasedir(), version, shallow);
        exitCode = GitCommandLineUtils.execute(clClone, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clClone.toString(), "The git-clone command failed.", stderr.getOutput(), false);
        }
        lastCommandLine = clClone.toString();
    }
    GitRemoteInfoCommand gitRemoteInfoCommand = new GitRemoteInfoCommand();
    gitRemoteInfoCommand.setLogger(getLogger());
    RemoteInfoScmResult result = gitRemoteInfoCommand.executeRemoteInfoCommand(repository, null, null);
    if (fileSet.getBasedir().exists() && new File(fileSet.getBasedir(), ".git").exists() && result.getBranches().size() > 0) {
        // git repo exists, so we must git-pull the changes
        Commandline clPull = createPullCommand(repository, fileSet.getBasedir(), version);
        exitCode = GitCommandLineUtils.execute(clPull, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clPull.toString(), "The git-pull command failed.", stderr.getOutput(), false);
        }
        lastCommandLine = clPull.toString();
        // and now lets do the git-checkout itself
        Commandline clCheckout = createCommandLine(repository, fileSet.getBasedir(), version);
        exitCode = GitCommandLineUtils.execute(clCheckout, stdout, stderr, getLogger());
        if (exitCode != 0) {
            return new CheckOutScmResult(clCheckout.toString(), "The git-checkout command failed.", stderr.getOutput(), false);
        }
        lastCommandLine = clCheckout.toString();
    }
    // and now search for the files
    GitListConsumer listConsumer = new GitListConsumer(getLogger(), fileSet.getBasedir(), ScmFileStatus.CHECKED_IN);
    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 CheckOutScmResult(lastCommandLine, 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) GitRemoteInfoCommand(org.apache.maven.scm.provider.git.gitexe.command.remoteinfo.GitRemoteInfoCommand) RemoteInfoScmResult(org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult) 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) 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