Search in sources :

Example 81 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class GitStatusConsumerTest method testConsumerModifiedFileInComplexDirectorySetup.

// SCM-740
public void testConsumerModifiedFileInComplexDirectorySetup() throws IOException {
    File dir = createTempDirectory();
    File subdir = new File(dir.getAbsolutePath() + "/subDirectory/");
    subdir.mkdir();
    FileUtils.write(new File(subdir, "project.xml"), "data");
    List<ScmFile> changedFiles = getChangedFiles("M  subDirectory/project.xml", subdir, dir.toURI());
    assertNotNull(changedFiles);
    assertEquals(1, changedFiles.size());
    assertEquals("subDirectory/project.xml", changedFiles.get(0).getPath());
    FileUtils.write(new File(subdir, "test file with spaces and a déjà vu character.xml"), "data");
    changedFiles = getChangedFiles("M  \"subDirectory/test file with spaces and a déjà vu character.xml\"", subdir, dir.toURI());
    assertNotNull(changedFiles);
    assertEquals(1, changedFiles.size());
    assertEquals("subDirectory/test file with spaces and a déjà vu character.xml", changedFiles.get(0).getPath());
    FileUtils.deleteDirectory(dir);
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 82 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class GitStatusConsumerTest method testConsumerAddedFileWithDirectoryAndFile.

public void testConsumerAddedFileWithDirectoryAndFile() throws IOException {
    File dir = createTempDirectory();
    FileUtils.write(new File(dir, "project.xml"), "data");
    List<ScmFile> changedFiles = getChangedFiles("A  project.xml", dir);
    assertNotNull(changedFiles);
    assertEquals(1, changedFiles.size());
    assertEquals("project.xml", changedFiles.get(0).getPath());
    FileUtils.write(new File(dir, "test file with spaces and a special \u007f character.xml"), "data");
    changedFiles = getChangedFiles("A  \"test file with spaces and a special \\177 character.xml\"", dir);
    assertNotNull(changedFiles);
    assertEquals(1, changedFiles.size());
    assertEquals("test file with spaces and a special \u007f character.xml", changedFiles.get(0).getPath());
    FileUtils.deleteDirectory(dir);
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 83 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class GitStatusConsumerTest method testConsumerRemovedFileWithDirectoryAndFile.

public void testConsumerRemovedFileWithDirectoryAndFile() throws IOException {
    File dir = createTempDirectory();
    FileUtils.write(new File(dir, "Capfile"), "data");
    List<ScmFile> changedFiles = getChangedFiles("D  Capfile", dir);
    assertNotNull(changedFiles);
    assertEquals(0, changedFiles.size());
    FileUtils.write(new File(dir, "test file with spaces and a special \u007f character.xml"), "data");
    changedFiles = getChangedFiles("D  \"test file with spaces and a special \\177 character.xml\"", dir);
    assertNotNull(changedFiles);
    assertEquals(0, changedFiles.size());
    FileUtils.deleteDirectory(dir);
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 84 with ScmFile

use of org.apache.maven.scm.ScmFile in project maven-scm by apache.

the class GitStatusConsumerTest method testConsumerRenamedFile.

// Test reproducing SCM-694
public void testConsumerRenamedFile() throws Exception {
    File dir = createTempDirectory();
    File tmpFile = new File(dir, "NewCapFile");
    FileUtils.write(tmpFile, "data");
    List<ScmFile> changedFiles = getChangedFiles("R  OldCapfile -> NewCapFile", dir);
    assertNotNull(changedFiles);
    assertEquals(2, changedFiles.size());
    assertEquals("OldCapfile", changedFiles.get(0).getPath());
    assertEquals("NewCapFile", changedFiles.get(1).getPath());
    tmpFile = new File(dir, "New test file with spaces and a special \u007f character.xml");
    FileUtils.write(tmpFile, "data");
    changedFiles = getChangedFiles("R  \"Old test file with spaces and a special \\177 character.xml\" -> \"New test file with spaces and a special \\177 character.xml\"", dir);
    assertNotNull(changedFiles);
    assertEquals(2, changedFiles.size());
    assertEquals("Old test file with spaces and a special \u007f character.xml", changedFiles.get(0).getPath());
    assertEquals("New test file with spaces and a special \u007f character.xml", changedFiles.get(1).getPath());
    FileUtils.deleteDirectory(dir);
}
Also used : ScmFile(org.apache.maven.scm.ScmFile) File(java.io.File) ScmFile(org.apache.maven.scm.ScmFile)

Example 85 with ScmFile

use of org.apache.maven.scm.ScmFile 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

ScmFile (org.apache.maven.scm.ScmFile)198 File (java.io.File)102 ArrayList (java.util.ArrayList)51 ScmException (org.apache.maven.scm.ScmException)34 BufferedReader (java.io.BufferedReader)21 DefaultLog (org.apache.maven.scm.log.DefaultLog)20 ScmFileStatus (org.apache.maven.scm.ScmFileStatus)19 ScmFileSet (org.apache.maven.scm.ScmFileSet)17 InputStreamReader (java.io.InputStreamReader)16 ScmResult (org.apache.maven.scm.ScmResult)15 StatusScmResult (org.apache.maven.scm.command.status.StatusScmResult)15 IOException (java.io.IOException)14 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)13 Matcher (java.util.regex.Matcher)11 AddScmResult (org.apache.maven.scm.command.add.AddScmResult)11 CheckOutScmResult (org.apache.maven.scm.command.checkout.CheckOutScmResult)10 UpdateScmResult (org.apache.maven.scm.command.update.UpdateScmResult)10 Commandline (org.codehaus.plexus.util.cli.Commandline)10 SynergyScmProviderRepository (org.apache.maven.scm.provider.synergy.repository.SynergyScmProviderRepository)9 FileInputStream (java.io.FileInputStream)8