Search in sources :

Example 21 with InMemoryStreamConsumer

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

the class GitCommandTest method shouldOutputSubmoduleRevisionsAfterUpdate.

@Test
public void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    InMemoryStreamConsumer outConsumer = new InMemoryStreamConsumer();
    gitWithSubmodule.resetWorkingDir(outConsumer, new StringRevision("HEAD"));
    Matcher matcher = Pattern.compile(".*^\\s[a-f0-9A-F]{40} sub1 \\(heads/master\\)$.*", Pattern.MULTILINE | Pattern.DOTALL).matcher(outConsumer.getAllOutput());
    assertThat(matcher.matches(), is(true));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) Matcher(java.util.regex.Matcher) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 22 with InMemoryStreamConsumer

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

the class GitCommandTest method shouldCloneFromMasterWhenNoBranchIsSpecified.

@Test
public void shouldCloneFromMasterWhenNoBranchIsSpecified() {
    InMemoryStreamConsumer output = inMemoryConsumer();
    git.clone(output, repoUrl);
    CommandLine commandLine = CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(gitLocalRepoDir);
    commandLine.run(output, "");
    assertThat(output.getStdOut(), Is.is("* master"));
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 23 with InMemoryStreamConsumer

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

the class GitCommandTest method shouldRetrieveSubmoduleUrls.

@Test
public void shouldRetrieveSubmoduleUrls() 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);
    Map<String, String> urls = gitWithSubmodule.submoduleUrls();
    assertThat(urls.size(), is(1));
    assertThat(urls.containsKey("sub1"), is(true));
    assertThat(urls.get("sub1"), endsWith(SUBMODULE));
}
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 24 with InMemoryStreamConsumer

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

the class GitCommandTest method shouldCloneFromBranchWhenMaterialPointsToABranch.

@Test
public void shouldCloneFromBranchWhenMaterialPointsToABranch() throws IOException {
    gitLocalRepoDir = createTempWorkingDirectory();
    git = new GitCommand(null, gitLocalRepoDir, BRANCH, false, new HashMap<>(), null);
    GitCommand branchedGit = new GitCommand(null, gitLocalRepoDir, BRANCH, false, new HashMap<>(), null);
    branchedGit.clone(inMemoryConsumer(), gitFooBranchBundle.projectRepositoryUrl());
    InMemoryStreamConsumer output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(gitLocalRepoDir).run(output, "");
    assertThat(output.getStdOut(), Is.is("* foo"));
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 25 with InMemoryStreamConsumer

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

the class HgCommandTest method shouldThrowExceptionIfUpdateFails.

@Test(expected = RuntimeException.class)
public void shouldThrowExceptionIfUpdateFails() throws Exception {
    InMemoryStreamConsumer output = ProcessOutputStreamConsumer.inMemoryConsumer();
    // delete repository in order to fail the hg pull command
    assertThat(FileUtils.deleteQuietly(serverRepo), is(true));
    // now hg pull will fail and throw an exception
    hgCommand.updateTo(new StringRevision("tip"), output);
}
Also used : 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