Search in sources :

Example 16 with GitTestRepo

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

the class GitCommandTest method shouldBombWhileRetrievingLatestModificationFromANonExistentRef.

@Test
public void shouldBombWhileRetrievingLatestModificationFromANonExistentRef() throws IOException {
    expectedException.expect(CommandLineException.class);
    expectedException.expectMessage("ambiguous argument 'origin/non-existent-branch': unknown revision or path not in the working tree.");
    GitTestRepo remoteRepo = new GitTestRepo();
    executeOnGitRepo("git", "remote", "rm", "origin");
    executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl());
    GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "non-existent-branch", false, new HashMap<>(), null);
    command.latestModification();
}
Also used : GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo)

Example 17 with GitTestRepo

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

the class GitCommandTest method shouldBombIfCheckedForModificationsSinceWithANonExistentRef.

@Test(expected = CommandLineException.class)
public void shouldBombIfCheckedForModificationsSinceWithANonExistentRef() throws IOException {
    GitTestRepo remoteRepo = new GitTestRepo();
    executeOnGitRepo("git", "remote", "rm", "origin");
    executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl());
    GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "non-existent-branch", false, new HashMap<>(), null);
    Modification modification = remoteRepo.checkInOneFile("foo", "Adding a commit").get(0);
    command.modificationsSince(new StringRevision(modification.getRevision()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision)

Example 18 with GitTestRepo

use of com.thoughtworks.go.domain.materials.git.GitTestRepo 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 19 with GitTestRepo

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

Example 20 with GitTestRepo

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

the class GitMaterialUpdaterTest method shouldConvertExistingRepoToFullRepoWhenShallowCloneIsOff.

@Test
public void shouldConvertExistingRepoToFullRepoWhenShallowCloneIsOff() throws IOException {
    String repositoryUrl = new GitTestRepo().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)

Aggregations

GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)25 Test (org.junit.Test)13 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)9 Modification (com.thoughtworks.go.domain.materials.Modification)7 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)4 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)1 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)1 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)1 SvnTestRepo (com.thoughtworks.go.helper.SvnTestRepo)1 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)1 MaterialService (com.thoughtworks.go.server.service.MaterialService)1