Search in sources :

Example 21 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class BranchCommandTckTest method testBranchCommandTest.

public void testBranchCommandTest() throws Exception {
    String branch = getBranch();
    @SuppressWarnings("deprecation") BranchScmResult branchResult = getScmManager().getProviderByUrl(getScmUrl()).branch(getScmRepository(), new ScmFileSet(getWorkingCopy()), branch);
    assertResultIsSuccess(branchResult);
    // see https://issues.apache.org/jira/browse/SCM-754
    // assertEquals( "check all 4 files branched", 4, branchResult.getBranchedFiles().size() );
    File readmeTxt = new File(getWorkingCopy(), "readme.txt");
    assertEquals("check readme.txt contents", "/readme.txt", FileUtils.fileRead(readmeTxt));
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    changeReadmeTxt(readmeTxt);
    CheckInScmResult checkinResult = getScmManager().checkIn(getScmRepository(), new ScmFileSet(getWorkingCopy()), "commit message");
    assertResultIsSuccess(checkinResult);
    CheckOutScmResult checkoutResult = getScmManager().checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()));
    assertResultIsSuccess(checkoutResult);
    readmeTxt = new File(getAssertionCopy(), "readme.txt");
    assertEquals("check readme.txt contents", "changed file", FileUtils.fileRead(readmeTxt));
    deleteDirectory(getAssertionCopy());
    assertFalse("check previous assertion copy deleted", getAssertionCopy().exists());
    checkoutResult = getScmManager().getProviderByUrl(getScmUrl()).checkOut(getScmRepository(), new ScmFileSet(getAssertionCopy()), new ScmBranch(branch));
    assertResultIsSuccess(checkoutResult);
    assertEquals("check readme.txt contents is from branched version", "/readme.txt", FileUtils.fileRead(readmeTxt));
}
Also used : ScmBranch(org.apache.maven.scm.ScmBranch) ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) BranchScmResult(org.apache.maven.scm.command.branch.BranchScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 22 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitCheckInCommandNoBranchTest method checkoutRepo.

protected CheckOutScmResult checkoutRepo(ScmRepository scmRepository) throws Exception {
    FileUtils.deleteDirectory(workingDirectory);
    CheckOutScmResult result = getScmManager().checkOut(scmRepository, new ScmFileSet(workingDirectory), (ScmVersion) null);
    assertResultIsSuccess(result);
    return result;
}
Also used : ScmFileSet(org.apache.maven.scm.ScmFileSet) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 23 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult 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 24 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitExeCheckOutCommandNoBranchTest method testCheckoutNoBranch.

public void testCheckoutNoBranch() throws Exception {
    if (!ScmTestCase.isSystemCmd("git")) {
        System.out.println("skip test which git native executable in path");
        return;
    }
    CheckOutScmResult result = checkoutRepo();
    assertEquals(0, result.getCheckedOutFiles().size());
}
Also used : CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Example 25 with CheckOutScmResult

use of org.apache.maven.scm.command.checkout.CheckOutScmResult in project maven-scm by apache.

the class GitExeCheckOutCommandNoBranchTest method testDoubleCheckoutNoBranch.

public void testDoubleCheckoutNoBranch() throws Exception {
    if (!ScmTestCase.isSystemCmd("git")) {
        System.out.println("skip test which git native executable in path");
        return;
    }
    CheckOutScmResult result = checkoutRepo();
    assertEquals(0, result.getCheckedOutFiles().size());
    CheckOutScmResult result2 = checkoutRepo();
    assertEquals(0, result2.getCheckedOutFiles().size());
}
Also used : CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult)

Aggregations

CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)57 File (java.io.File)24 ScmFileSet (org.apache.maven.scm.ScmFileSet)20 ScmFile (org.apache.maven.scm.ScmFile)14 ScmException (org.apache.maven.scm.ScmException)11 ScmTag (org.apache.maven.scm.ScmTag)9 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)9 Commandline (org.codehaus.plexus.util.cli.Commandline)8 Test (org.junit.Test)8 CommandParameters (org.apache.maven.scm.CommandParameters)7 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)7 IOException (java.io.IOException)6 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 ScmManager (org.apache.maven.scm.manager.ScmManager)5 ScmRepository (org.apache.maven.scm.repository.ScmRepository)5 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)5 ArrayList (java.util.ArrayList)4 ScmResult (org.apache.maven.scm.ScmResult)4 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)3