Search in sources :

Example 31 with StringRevision

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

the class GitCommandTest method shouldBombIfCheckedForModificationsSinceWithASHAThatNoLongerExists.

@Test(expected = CommandLineException.class)
public void shouldBombIfCheckedForModificationsSinceWithASHAThatNoLongerExists() throws IOException {
    GitTestRepo remoteRepo = new GitTestRepo(temporaryFolder);
    executeOnGitRepo("git", "remote", "rm", "origin");
    executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl());
    GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "master", false, new HashMap<>(), null);
    Modification modification = remoteRepo.checkInOneFile("foo", "Adding a commit").get(0);
    remoteRepo.addFileAndAmend("bar", "amendedCommit");
    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) Test(org.junit.Test)

Example 32 with StringRevision

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

the class GitCommandTest method shouldBombForResetWorkingDirWhenSubmoduleUpdateFails.

@Test
public void shouldBombForResetWorkingDirWhenSubmoduleUpdateFails() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    File submoduleFolder = submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    FileUtils.deleteDirectory(submoduleFolder);
    assertThat(submoduleFolder.exists(), is(false));
    try {
        gitWithSubmodule.resetWorkingDir(new SysOutStreamConsumer(), new StringRevision("HEAD"));
        fail("should have failed for non 0 return code");
    } catch (Exception e) {
        assertThat(e.getMessage(), 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) SysOutStreamConsumer(com.thoughtworks.go.mail.SysOutStreamConsumer) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 33 with StringRevision

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

the class GitCommandTest method shouldBombForResettingFailure.

@Test
public void shouldBombForResettingFailure() throws IOException {
    try {
        git.resetWorkingDir(new SysOutStreamConsumer(), new StringRevision("abcdef"));
        fail("should have failed for non 0 return code");
    } catch (Exception e) {
        assertThat(e.getMessage(), is(String.format("git reset failed for [%s]", gitLocalRepoDir)));
    }
}
Also used : SysOutStreamConsumer(com.thoughtworks.go.mail.SysOutStreamConsumer) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 34 with StringRevision

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

the class GitCommandTest method shouldOutputSubmoduleRevisionsAfterUpdate.

@Test
public void shouldOutputSubmoduleRevisionsAfterUpdate() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
    submoduleRepos.addSubmodule(SUBMODULE, "sub1");
    GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    gitWithSubmodule.clone(inMemoryConsumer(), submoduleRepos.mainRepo().getUrl());
    InMemoryStreamConsumer outConsumer = new InMemoryStreamConsumer();
    gitWithSubmodule.resetWorkingDir(outConsumer, new StringRevision("HEAD"));
    Matcher matcher = Pattern.compile(".*^\\s[a-f0-9A-F]{40} sub1 \\(heads/master\\)$.*", Pattern.MULTILINE | Pattern.DOTALL).matcher(outConsumer.getAllOutput());
    assertThat(matcher.matches(), is(true));
}
Also used : GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) Matcher(java.util.regex.Matcher) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) RegexMatcher(com.thoughtworks.go.matchers.RegexMatcher) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 35 with StringRevision

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

the class GitCommandTest method shouldBombIfCheckedForModificationsSinceWithANonExistentRef.

@Test(expected = CommandLineException.class)
public void shouldBombIfCheckedForModificationsSinceWithANonExistentRef() throws IOException {
    GitTestRepo remoteRepo = new GitTestRepo(temporaryFolder);
    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) Test(org.junit.Test)

Aggregations

StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)65 Test (org.junit.Test)35 File (java.io.File)31 Test (org.junit.jupiter.api.Test)23 Modification (com.thoughtworks.go.domain.materials.Modification)17 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)17 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)11 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)7 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)6 TestSubprocessExecutionContext (com.thoughtworks.go.domain.materials.TestSubprocessExecutionContext)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 StringContains.containsString (org.hamcrest.core.StringContains.containsString)5 RegexMatcher (com.thoughtworks.go.matchers.RegexMatcher)4 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)3 JsonValue (com.thoughtworks.go.util.JsonValue)3 Changeset (com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Changeset)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)2 SysOutStreamConsumer (com.thoughtworks.go.mail.SysOutStreamConsumer)2