Search in sources :

Example 6 with RevisionContext

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

the class GitMaterialUpdaterTest method shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo.

@Test
public void shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitMaterial gitMaterial = new GitMaterial(submoduleRepos.mainRepo().getUrl(), true);
    StringRevision revision = new StringRevision("origin/master");
    updateTo(gitMaterial, new RevisionContext(revision), JobResult.Passed);
    assertThat(new File(workingDir, "sub1"), exists());
    submoduleRepos.removeSubmodule("sub1");
    updateTo(gitMaterial, new RevisionContext(revision), JobResult.Passed);
    assertThat(new File(workingDir, "sub1"), not(exists()));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) File(java.io.File) Test(org.junit.Test)

Example 7 with RevisionContext

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

the class GitMaterialUpdaterTest method shouldAllowSubmoduleUrlstoChange.

@Test
public void shouldAllowSubmoduleUrlstoChange() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    String submoduleDirectoryName = "local-submodule";
    submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    assertThat(console.output(), containsString("Synchronizing submodule url for 'local-submodule'"));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 8 with RevisionContext

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

the class GitMaterialUpdaterTest method cloneWithDeepWorkingDir.

@Test
public void cloneWithDeepWorkingDir() throws Exception {
    GitMaterial material = new GitMaterial(new GitTestRepo().projectRepositoryUrl(), "", "foo/bar/baz", true);
    updateTo(material, new RevisionContext(REVISION_4), JobResult.Passed);
    assertThat(new File(workingDir, "foo/bar/baz/build.xml").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)

Example 9 with RevisionContext

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

the class SvnMaterialMockitoTest method shouldNotDeleteWorkingDirIfSvnRepositoryUsesFileProtocol.

@Test
public void shouldNotDeleteWorkingDirIfSvnRepositoryUsesFileProtocol() throws IOException {
    Subversion subversion = mock(Subversion.class);
    when(subversion.getUserName()).thenReturn("");
    when(subversion.getPassword()).thenReturn("");
    when(subversion.isCheckExternals()).thenReturn(false);
    File workingCopy = createSvnWorkingCopy(true);
    when(subversion.workingRepositoryUrl(workingCopy)).thenReturn(workingCopy.getPath());
    String url = "file://" + workingCopy.getPath();
    when(subversion.getUrl()).thenReturn(new UrlArgument(url));
    SvnMaterial svnMaterial = SvnMaterial.createSvnMaterialWithMock(subversion);
    svnMaterial.setUrl(url);
    svnMaterial.updateTo(outputStreamConsumer, workingCopy, new RevisionContext(revision), new TestSubprocessExecutionContext());
    assertThat(workingCopy.exists(), is(true));
    verify(subversion).updateTo(outputStreamConsumer, workingCopy, revision);
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) TestSubprocessExecutionContext(com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) File(java.io.File) Test(org.junit.Test)

Example 10 with RevisionContext

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

the class BackupServiceIntegrationTest method shouldBackupConfigRepository.

@Test
public void shouldBackupConfigRepository() throws IOException {
    configHelper.addPipeline("too-unique-to-be-present", "stage-name");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    backupService.startBackup(admin, result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(result.message(localizer), is("Backup completed successfully."));
    File repoZip = backedUpFile("config-repo.zip");
    File repoDir = tempFiles.createUniqueFolder("expanded-config-repo-backup");
    TestUtils.extractZipToDir(repoZip, repoDir);
    File cloneDir = tempFiles.createUniqueFolder("cloned-config-repo-backup");
    GitMaterial git = new GitMaterial(repoDir.getAbsolutePath());
    List<Modification> modifications = git.latestModification(cloneDir, subprocessExecutionContext);
    String latestChangeRev = modifications.get(0).getRevision();
    git.checkout(cloneDir, new StringRevision(latestChangeRev), subprocessExecutionContext);
    assertThat(FileUtil.readContentFromFile(new File(cloneDir, "cruise-config.xml")).indexOf("too-unique-to-be-present"), greaterThan(0));
    StringRevision revision = new StringRevision(latestChangeRev + "~1");
    git.updateTo(new InMemoryStreamConsumer(), cloneDir, new RevisionContext(revision), subprocessExecutionContext);
    assertThat(FileUtil.readContentFromFile(new File(cloneDir, "cruise-config.xml")).indexOf("too-unique-to-be-present"), is(-1));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) 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