Search in sources :

Example 16 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitCommandTest method shouldBombForResetWorkingDirWhenSubmoduleUpdateFails.

@Test
public void shouldBombForResetWorkingDirWhenSubmoduleUpdateFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    File submoduleFolder = submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    FileUtils.deleteDirectory(submoduleFolder);
    assertThat(submoduleFolder.exists(), is(false));
    try {
        gitWithSubmodule.resetWorkingDir(new SysOutStreamConsumer(), new StringRevision("HEAD"));
        fail("should have failed for non 0 return code");
    } catch (Exception e) {
        assertThat(e.getMessage(), new RegexMatcher(String.format("[Cc]lone of '%s' into submodule path '((.*)[\\/])?sub1' failed", Pattern.quote(submoduleFolder.getAbsolutePath()))));
    }
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) SysOutStreamConsumer(com.thoughtworks.go.mail.SysOutStreamConsumer) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException)

Example 17 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitCommandTest method shouldRetrieveSubmoduleUrls.

@Test
public void shouldRetrieveSubmoduleUrls() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    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) StringContains.containsString(org.hamcrest.core.StringContains.containsString)

Example 18 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitCommandTest method shouldOutputSubmoduleRevisionsAfterUpdate.

@Test
public void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    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) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision)

Example 19 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldBombForFetchAndResetWhenSubmoduleUpdateFails.

@Test
public void shouldBombForFetchAndResetWhenSubmoduleUpdateFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    File submoduleFolder = submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    FileUtils.deleteDirectory(submoduleFolder);
    assertThat(submoduleFolder.exists(), Matchers.is(false));
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Failed);
    assertThat(console.output(), // git on windows prints full submodule paths
    new RegexMatcher(String.format("[Cc]lone of '%s' into submodule path '((.*)[\\/])?sub1' failed", Pattern.quote(submoduleFolder.getAbsolutePath()))));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) File(java.io.File) Test(org.junit.Test)

Example 20 with GitSubmoduleRepos

use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldOutputSubmoduleRevisionsAfterUpdate.

@Test
public void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    Matcher matcher = Pattern.compile(".*^\\s[a-f0-9A-F]{40} sub1 \\(heads/master\\)$.*", Pattern.MULTILINE | Pattern.DOTALL).matcher(console.output());
    assertThat(matcher.matches(), Matchers.is(true));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) Matcher(java.util.regex.Matcher) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) Test(org.junit.Test)

Aggregations

GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)22 File (java.io.File)13 Test (org.junit.Test)12 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)6 RandomAccessFile (java.io.RandomAccessFile)5 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)4 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)4 Materials (com.thoughtworks.go.config.materials.Materials)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 Matcher (java.util.regex.Matcher)2 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 SysOutStreamConsumer (com.thoughtworks.go.mail.SysOutStreamConsumer)1 IOException (java.io.IOException)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1