Search in sources :

Example 6 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitCommandTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    File cloneDirectory = createTempWorkingDirectory();
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    /* Simulate an agent checkout of code. */
    GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
    /* Simulate a local modification of file inside submodule, on agent side. */
    File fileInSubmodule = allFilesIn(new File(cloneDirectory, submoduleDirectoryName), "file-").get(0);
    FileUtils.writeStringToFile(fileInSubmodule, "Some other new content.", UTF_8);
    /* Commit a change to the file on the repo. */
    List<Modification> modifications = submoduleRepos.modifyOneFileInSubmoduleAndUpdateMainRepo(remoteSubmoduleLocation, submoduleDirectoryName, fileInSubmodule.getName(), "NEW CONTENT OF FILE");
    /* Simulate start of a new build on agent. */
    clonedCopy.fetch(outputStreamConsumer);
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision(modifications.get(0).getRevision()));
    assertThat(FileUtils.readFileToString(fileInSubmodule, UTF_8), is("NEW CONTENT OF FILE"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 7 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitCommandTest method shouldAllowSubmoduleUrlstoChange.

@Test
public void shouldAllowSubmoduleUrlstoChange() throws Exception {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    String submoduleDirectoryName = "local-submodule";
    File cloneDirectory = createTempWorkingDirectory();
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    clonedCopy.fetchAndResetToHead(outputStreamConsumer);
    submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName);
    clonedCopy.fetchAndResetToHead(outputStreamConsumer);
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) Test(org.junit.Test)

Example 8 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitCommandTest method shouldNotFailIfUnableToRemoveSubmoduleEntryFromConfig.

@Test
public void shouldNotFailIfUnableToRemoveSubmoduleEntryFromConfig() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    gitWithSubmodule.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    gitWithSubmodule.fetchAndResetToHead(outputStreamConsumer);
    gitWithSubmodule.updateSubmoduleWithInit(outputStreamConsumer);
    List<String> folders = gitWithSubmodule.submoduleFolders();
    assertThat(folders.size(), is(1));
    assertThat(folders.get(0), is("sub1"));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 9 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitCommandTest method shouldBombForFetchFailure.

@Test
public void shouldBombForFetchFailure() throws IOException {
    executeOnGitRepo("git", "remote", "rm", "origin");
    executeOnGitRepo("git", "remote", "add", "origin", "git://user:secret@foo.bar/baz");
    try {
        InMemoryStreamConsumer output = new InMemoryStreamConsumer();
        git.fetch(output);
        fail("should have failed for non 0 return code. Git output was:\n " + output.getAllOutput());
    } catch (Exception e) {
        assertThat(e.getMessage(), is("git fetch failed for [git://user:******@foo.bar/baz]"));
    }
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitCommandTest method shouldNotThrowErrorWhenConfigRemoveSectionFails.

@Test
public void shouldNotThrowErrorWhenConfigRemoveSectionFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null) {

        // hack to reproduce synchronization issue
        @Override
        public Map<String, String> submoduleUrls() {
            return Collections.singletonMap("submodule", "submodule");
        }
    };
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    gitWithSubmodule.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    gitWithSubmodule.updateSubmoduleWithInit(outputStreamConsumer);
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) StringContains.containsString(org.hamcrest.core.StringContains.containsString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Aggregations

InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)31 Test (org.junit.Test)17 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)8 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)7 File (java.io.File)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 Test (org.junit.jupiter.api.Test)5 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)4 CommandLine (com.thoughtworks.go.util.command.CommandLine)4 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 Modification (com.thoughtworks.go.domain.materials.Modification)3 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)2 P4Client (com.thoughtworks.go.domain.materials.perforce.P4Client)2 IOException (java.io.IOException)2 SubprocessExecutionContext (com.thoughtworks.go.config.materials.SubprocessExecutionContext)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)1 PluggableSCMMaterialAgent (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent)1