Search in sources :

Example 21 with RevisionContext

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

the class GitMaterialUpdaterTest method shouldConvertExistingRepoToFullRepoWhenShallowCloneIsOff.

@Test
public void shouldConvertExistingRepoToFullRepoWhenShallowCloneIsOff() throws IOException {
    String repositoryUrl = new GitTestRepo(temporaryFolder).projectRepositoryUrl();
    GitMaterial shallowMaterial = new GitMaterial(repositoryUrl, true);
    updateTo(shallowMaterial, new RevisionContext(REVISION_3), JobResult.Passed);
    assertThat(localRepoFor(shallowMaterial).isShallow(), is(true));
    GitMaterial fullMaterial = new GitMaterial(repositoryUrl, false);
    updateTo(fullMaterial, new RevisionContext(REVISION_4), JobResult.Passed);
    assertThat(localRepoFor(fullMaterial).isShallow(), is(false));
}
Also used : RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 22 with RevisionContext

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

the class GitMaterialUpdaterTest method shouldNotDeleteAndRecheckoutDirectoryWhenBranchIsBlank.

/* This is to test the functionality of the private method isRepositoryChanged() */
@Test
public void shouldNotDeleteAndRecheckoutDirectoryWhenBranchIsBlank() throws Exception {
    String repositoryUrl = new GitTestRepo(temporaryFolder).projectRepositoryUrl();
    GitMaterial material = new GitMaterial(repositoryUrl, false);
    updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    File shouldNotBeRemoved = new File(new File(workingDir, ".git"), "shouldNotBeRemoved");
    FileUtils.writeStringToFile(shouldNotBeRemoved, "Text file", UTF_8);
    GitMaterial material1 = new GitMaterial(repositoryUrl, " ");
    updateTo(material1, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    assertThat("Should not have deleted whole folder", shouldNotBeRemoved.exists(), is(true));
}
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)

Example 23 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", temporaryFolder);
    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 24 with RevisionContext

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

the class GitMaterialUpdaterTest method shouldNotDeleteAndRecheckoutDirectoryWhenUrlSame.

@Test
public void shouldNotDeleteAndRecheckoutDirectoryWhenUrlSame() throws Exception {
    GitMaterial material = new GitMaterial(new GitTestRepo(temporaryFolder).projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    File shouldNotBeRemoved = new File(new File(workingDir, ".git"), "shouldNotBeRemoved");
    FileUtils.writeStringToFile(shouldNotBeRemoved, "gundi", UTF_8);
    assertThat(shouldNotBeRemoved.exists(), is(true));
    updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    assertThat("Should not have deleted whole folder", shouldNotBeRemoved.exists(), is(true));
}
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) File(java.io.File) Test(org.junit.Test)

Example 25 with RevisionContext

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

the class GitMaterialUpdaterTest method shouldCreateBuildCommandUpdateToSpecificRevision.

@Test
public void shouldCreateBuildCommandUpdateToSpecificRevision() throws Exception {
    GitMaterial material = new GitMaterial(new GitTestRepo(temporaryFolder).projectRepositoryUrl(), true);
    File newFile = new File(workingDir, "second.txt");
    updateTo(material, new RevisionContext(REVISION_1, REVISION_0, 2), JobResult.Passed);
    assertThat(console.output(), containsString("Start updating files at revision " + REVISION_1.getRevision()));
    assertThat(newFile.exists(), is(false));
    console.clear();
    updateTo(material, new RevisionContext(REVISION_2, REVISION_1, 2), JobResult.Passed);
    assertThat(console.output(), containsString("Start updating files at revision " + REVISION_2.getRevision()));
    assertThat(newFile.exists(), is(true));
}
Also used : RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) File(java.io.File) Test(org.junit.Test)

Aggregations

RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)43 Test (org.junit.Test)37 File (java.io.File)23 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)17 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)6 Modification (com.thoughtworks.go.domain.materials.Modification)5 Test (org.junit.jupiter.api.Test)4 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 TestSubprocessExecutionContext (com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext)2 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)2 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)1 AgentSubprocessExecutionContext (com.thoughtworks.go.domain.materials.AgentSubprocessExecutionContext)1 Revision (com.thoughtworks.go.domain.materials.Revision)1 SvnTestRepo (com.thoughtworks.go.helper.SvnTestRepo)1