Search in sources :

Example 11 with RevisionContext

use of com.thoughtworks.go.domain.materials.RevisionContext in project gocd by gocd.

the class GitMaterialShallowCloneTest method updateToANewRevisionShouldNotResultInUnshallowing.

@Test
public void updateToANewRevisionShouldNotResultInUnshallowing() throws IOException {
    GitMaterial material = new GitMaterial(repo.projectRepositoryUrl(), true);
    material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(REVISION_4, REVISION_4, 1), context());
    assertThat(localRepoFor(material).isShallow(), is(true));
    List<Modification> modifications = repo.addFileAndPush("newfile", "add new file");
    StringRevision newRevision = new StringRevision(modifications.get(0).getRevision());
    material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(newRevision, newRevision, 1), context());
    assertThat(new File(workingDir, "newfile").exists(), is(true));
    assertThat(localRepoFor(material).isShallow(), is(true));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) File(java.io.File) Test(org.junit.Test)

Example 12 with RevisionContext

use of com.thoughtworks.go.domain.materials.RevisionContext 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 13 with RevisionContext

use of com.thoughtworks.go.domain.materials.RevisionContext in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldDeleteAndRecheckoutDirectoryWhenBranchChanges.

@Test
public void shouldDeleteAndRecheckoutDirectoryWhenBranchChanges() throws Exception {
    GitTestRepo repoWithBranch = GitTestRepo.testRepoAtBranch(GIT_FOO_BRANCH_BUNDLE, "foo");
    GitMaterial material = new GitMaterial(repoWithBranch.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    InMemoryStreamConsumer output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(workingDir).run(output, "");
    assertThat(output.getStdOut(), Is.is("* master"));
    GitMaterial material1 = new GitMaterial(repoWithBranch.projectRepositoryUrl(), "foo", null, true);
    updateTo(material1, new RevisionContext(new StringRevision("origin/foo")), JobResult.Passed);
    output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(workingDir).run(output, "");
    assertThat(output.getStdOut(), Is.is("* foo"));
}
Also used : RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 14 with RevisionContext

use of com.thoughtworks.go.domain.materials.RevisionContext 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)

Example 15 with RevisionContext

use of com.thoughtworks.go.domain.materials.RevisionContext in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldDeleteAndRecheckoutDirectoryWhenUrlChanges.

@Test
public void shouldDeleteAndRecheckoutDirectoryWhenUrlChanges() throws Exception {
    updateTo(new GitMaterial(new GitTestRepo().projectRepositoryUrl(), true), new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    File shouldBeRemoved = new File(workingDir, "shouldBeRemoved");
    shouldBeRemoved.createNewFile();
    assertThat(shouldBeRemoved.exists(), is(true));
    String repositoryUrl = new GitTestRepo().projectRepositoryUrl();
    GitMaterial material = new GitMaterial(repositoryUrl, true);
    updateTo(material, new RevisionContext(REVISION_4), JobResult.Passed);
    assertThat(localRepoFor(material).workingRepositoryUrl().forCommandline(), is(repositoryUrl));
    assertThat(shouldBeRemoved.exists(), is(false));
}
Also used : RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Aggregations

RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)20 Test (org.junit.Test)20 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)13 File (java.io.File)13 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)6 Modification (com.thoughtworks.go.domain.materials.Modification)3 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)2 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 TestSubprocessExecutionContext (com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)1 Matcher (java.util.regex.Matcher)1