Search in sources :

Example 36 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class GitCheckInCommandNoBranchTest method testCheckinNoBranch.

public void testCheckinNoBranch() throws Exception {
    if (!ScmTestCase.isSystemCmd("git")) {
        System.out.println("skip test which git native executable in path");
        return;
    }
    File repo_orig = new File("src/test/resources/repository_no_branch");
    File repo = getTestFile("target/git_copy");
    FileUtils.deleteDirectory(repo);
    FileUtils.copyDirectoryStructure(repo_orig, repo);
    ScmRepository scmRepository = getScmManager().makeScmRepository("scm:git:file:///" + repo.getAbsolutePath());
    CheckOutScmResult checkOutScmResult = checkoutRepo(scmRepository);
    assertEquals(0, checkOutScmResult.getCheckedOutFiles().size());
    File f = new File(workingDirectory.getAbsolutePath() + File.separator + "pom.xml");
    FileUtils.fileWrite(f.getAbsolutePath(), "toto");
    ScmFileSet scmFileSet = new ScmFileSet(workingDirectory, new File("pom.xml"));
    AddScmResult addResult = getScmManager().add(scmRepository, scmFileSet);
    assertResultIsSuccess(addResult);
    CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, scmFileSet, "commit");
    assertResultIsSuccess(checkInScmResult);
    assertEquals(1, checkInScmResult.getCheckedInFiles().size());
    assertEquals("pom.xml", checkInScmResult.getCheckedInFiles().get(0).getPath());
    checkOutScmResult = checkoutRepo(scmRepository);
    assertResultIsSuccess(checkOutScmResult);
    assertEquals(1, checkOutScmResult.getCheckedOutFiles().size());
    assertEquals("pom.xml", checkOutScmResult.getCheckedOutFiles().get(0).getPath());
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) CheckOutScmResult(org.apache.maven.scm.command.checkout.CheckOutScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult)

Example 37 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class JGitAddCommand method executeAddCommand.

/**
 * {@inheritDoc}
 */
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
    if (fileSet.getFileList().isEmpty()) {
        throw new ScmException("You must provide at least one file/directory to add (e.g. -Dincludes=...)");
    }
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        List<ScmFile> addedFiles = JGitUtils.addAllFiles(git, fileSet);
        if (getLogger().isDebugEnabled()) {
            for (ScmFile scmFile : addedFiles) {
                getLogger().info("added file: " + scmFile);
            }
        }
        return new AddScmResult("JGit add", addedFiles);
    } catch (Exception e) {
        throw new ScmException("JGit add failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) ScmException(org.apache.maven.scm.ScmException) ScmFile(org.apache.maven.scm.ScmFile)

Example 38 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class GitCheckInCommandTest method testCheckinAfterRename.

// Test reproducing SCM-694
public void testCheckinAfterRename() throws Exception {
    File repo = getRepositoryRoot();
    File checkedOutRepo = getWorkingCopy();
    GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());
    ScmRepository scmRepository = getScmManager().makeScmRepository("scm:git:file://" + repo.getAbsolutePath());
    checkoutRepoInto(checkedOutRepo, scmRepository);
    // Creating foo/bar/wine.xml
    File fooDir = new File(checkedOutRepo.getAbsolutePath() + File.separator + "foo");
    fooDir.mkdir();
    File barDir = new File(fooDir.getAbsolutePath() + File.separator + "bar");
    barDir.mkdir();
    File wineFile = new File(barDir.getAbsolutePath() + File.separator + "wine.xml");
    FileUtils.fileWrite(wineFile.getAbsolutePath(), "Lacoste castle");
    // Adding and commiting file
    AddScmResult addResult = getScmManager().add(scmRepository, new ScmFileSet(checkedOutRepo, new File("foo/bar/wine.xml")));
    assertResultIsSuccess(addResult);
    CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, new ScmFileSet(checkedOutRepo), "Created wine file");
    assertResultIsSuccess(checkInScmResult);
    // Cloning foo/bar/wine.xml to foo/newbar/wine.xml
    File newBarDir = new File(fooDir.getAbsolutePath() + File.separator + "newbar");
    newBarDir.mkdir();
    File movedWineFile = new File(newBarDir.getAbsolutePath() + File.separator + "wine.xml");
    FileUtils.copyFile(wineFile, movedWineFile);
    // Removing old file, adding new file and commiting...
    RemoveScmResult removeResult = getScmManager().remove(scmRepository, new ScmFileSet(checkedOutRepo, new File("foo/bar/")), "");
    assertResultIsSuccess(removeResult);
    addResult = getScmManager().add(scmRepository, new ScmFileSet(checkedOutRepo, new File("foo/newbar/wine.xml")));
    assertResultIsSuccess(addResult);
    checkInScmResult = getScmManager().checkIn(scmRepository, new ScmFileSet(checkedOutRepo), "moved wine.xml from foo/bar/ to foo/newbar/");
    assertResultIsSuccess(checkInScmResult);
    assertTrue("Renamed file has not been commited !", checkInScmResult.getCheckedInFiles().size() != 0);
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) AddScmResult(org.apache.maven.scm.command.add.AddScmResult) File(java.io.File) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) RemoveScmResult(org.apache.maven.scm.command.remove.RemoveScmResult)

Example 39 with AddScmResult

use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.

the class GitAddCommand method executeAddFiles.

private AddScmResult executeAddFiles(File workingDirectory, List<File> files) throws ScmException {
    Commandline cl = createCommandLine(workingDirectory, files);
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
    int exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
    if (exitCode != 0) {
        return new AddScmResult(cl.toString(), "The git-add command failed.", stderr.getOutput(), false);
    }
    return null;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) AddScmResult(org.apache.maven.scm.command.add.AddScmResult)

Aggregations

AddScmResult (org.apache.maven.scm.command.add.AddScmResult)39 File (java.io.File)18 ScmFile (org.apache.maven.scm.ScmFile)12 ScmFileSet (org.apache.maven.scm.ScmFileSet)9 ScmException (org.apache.maven.scm.ScmException)8 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 ArrayList (java.util.ArrayList)6 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)6 Commandline (org.codehaus.plexus.util.cli.Commandline)6 CommandParameters (org.apache.maven.scm.CommandParameters)4 ScmRepository (org.apache.maven.scm.repository.ScmRepository)4 ScmResult (org.apache.maven.scm.ScmResult)3 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)3 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ScmFileMatcher.assertHasScmFile (org.apache.maven.scm.ScmFileMatcher.assertHasScmFile)2 AbstractAccuRevCommandTest (org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)2 GitCommandLineUtils (org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils)2 JazzScmCommand (org.apache.maven.scm.provider.jazz.command.JazzScmCommand)2