Search in sources :

Example 1 with GitTestRepo

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

the class GitMaterialTest method setup.

@Before
public void setup() throws Exception {
    temporaryFolder.create();
    GitTestRepo gitRepo = new GitTestRepo(temporaryFolder);
    outputStreamConsumer = inMemoryConsumer();
    workingDir = temporaryFolder.newFolder("workingDir-" + System.currentTimeMillis());
    repositoryUrl = gitRepo.projectRepositoryUrl();
    git = new GitMaterial(repositoryUrl);
    gitFooBranchBundle = GitTestRepo.testRepoAtBranch(GIT_FOO_BRANCH_BUNDLE, BRANCH, temporaryFolder);
}
Also used : GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) Before(org.junit.Before)

Example 2 with GitTestRepo

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

the class GitMaterialTest method shouldGetLatestModificationFromBranch.

@Test
public void shouldGetLatestModificationFromBranch() throws Exception {
    GitTestRepo branchedTestRepo = GitTestRepo.testRepoAtBranch(GIT_FOO_BRANCH_BUNDLE, BRANCH, temporaryFolder);
    GitMaterial branchedGit = new GitMaterial(branchedTestRepo.projectRepositoryUrl(), BRANCH);
    List<Modification> modifications = branchedGit.latestModification(temporaryFolder.newFolder(), new TestSubprocessExecutionContext());
    assertThat(modifications.size(), is(1));
    assertThat(modifications.get(0).getComment(), Matchers.is("Started foo branch"));
}
Also used : GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) Test(org.junit.Test)

Example 3 with GitTestRepo

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

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered.

@Test
public void shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered() throws Exception {
    GitTestRepo otherGitRepo = new GitTestRepo(temporaryFolder);
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
    pipelineConfig.materialConfigs().clear();
    materialConfig = hgRepo.createMaterialConfig("dest1");
    materialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(materialConfig);
    // new material is added
    GitMaterial gitMaterial = otherGitRepo.createMaterial("dest2");
    gitMaterial.setAutoUpdate(true);
    MaterialConfig otherMaterialConfig = gitMaterial.config();
    otherMaterialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(otherMaterialConfig);
    List<Modification> mod = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    Map<String, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(20);
    assertThat(afterLoad.keySet(), hasItem(PIPELINE_NAME));
    BuildCause cause = afterLoad.get(PIPELINE_NAME);
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = mod.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat(pipelineConfig.materialConfigs(), hasItem(otherMaterialConfig));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
    // update of commited material happened during manual trigger
    MaterialRevisions modificationsInDb = materialRepository.findLatestModification(gitMaterial);
    assertThat(modificationsInDb.latestRevision(), is(otherGitRepo.latestModification().get(0).getRevision()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.Test)

Example 4 with GitTestRepo

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

the class ScheduledPipelineLoaderIntegrationTest method shouldLoadShallowCloneFlagForGitMaterialsBaseOnTheirOwnPipelineConfig.

@Test
public void shouldLoadShallowCloneFlagForGitMaterialsBaseOnTheirOwnPipelineConfig() throws IOException {
    GitTestRepo testRepo = new GitTestRepo(temporaryFolder);
    PipelineConfig shallowPipeline = PipelineConfigMother.pipelineConfig("shallowPipeline", new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    shallowPipeline.materialConfigs().clear();
    shallowPipeline.addMaterialConfig(new GitMaterialConfig(testRepo.projectRepositoryUrl(), null, true));
    configHelper.addPipeline(shallowPipeline);
    PipelineConfig fullPipeline = PipelineConfigMother.pipelineConfig("fullPipeline", new StageConfig(new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    fullPipeline.materialConfigs().clear();
    fullPipeline.addMaterialConfig(new GitMaterialConfig(testRepo.projectRepositoryUrl(), null, false));
    configHelper.addPipeline(fullPipeline);
    Pipeline shallowPipelineInstance = createAndLoadModifyOneFilePipeline(shallowPipeline);
    MaterialRevisions shallowRevisions = shallowPipelineInstance.getBuildCause().getMaterialRevisions();
    assertThat(((GitMaterial) shallowRevisions.getRevisions().get(0).getMaterial()).isShallowClone(), is(true));
    Pipeline fullPipelineInstance = createAndLoadModifyOneFilePipeline(fullPipeline);
    MaterialRevisions fullRevisions = fullPipelineInstance.getBuildCause().getMaterialRevisions();
    assertThat(((GitMaterial) fullRevisions.getRevisions().get(0).getMaterial()).isShallowClone(), is(false));
}
Also used : GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) Test(org.junit.Test)

Example 5 with GitTestRepo

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

the class GitCommandTest method shouldRetrieveLatestModificationFromBranch.

@Test
public void shouldRetrieveLatestModificationFromBranch() throws Exception {
    GitTestRepo branchedRepo = GitTestRepo.testRepoAtBranch(GIT_FOO_BRANCH_BUNDLE, BRANCH, temporaryFolder);
    GitCommand branchedGit = new GitCommand(null, createTempWorkingDirectory(), BRANCH, false, new HashMap<>(), null);
    branchedGit.clone(inMemoryConsumer(), branchedRepo.projectRepositoryUrl());
    Modification mod = branchedGit.latestModification().get(0);
    assertThat(mod.getUserName(), is("Chris Turner <cturner@thoughtworks.com>"));
    assertThat(mod.getComment(), is("Started foo branch"));
    assertThat(mod.getModifiedTime(), is(parseRFC822("Tue, 05 Feb 2009 14:28:08 -0800")));
    assertThat(mod.getRevision(), is("b4fa7271c3cef91822f7fa502b999b2eab2a380d"));
    List<ModifiedFile> files = mod.getModifiedFiles();
    assertThat(files.size(), is(1));
    assertThat(files.get(0).getFileName(), is("first.txt"));
    assertThat(files.get(0).getAction(), is(ModifiedAction.modified));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) Test(org.junit.Test)

Aggregations

GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)31 Test (org.junit.Test)20 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)9 Modification (com.thoughtworks.go.domain.materials.Modification)8 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)7 File (java.io.File)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Before (org.junit.Before)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)3 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)3 SvnTestRepo (com.thoughtworks.go.helper.SvnTestRepo)3 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)2 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)2 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)2 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)2 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)2 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)2