Search in sources :

Example 6 with Modification

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

the class GitMaterialUpdaterTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    String submoduleDirectoryName = "local-submodule";
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
    /* Simulate a local modification of file inside submodule, on agent side. */
    File fileInSubmodule = allFilesIn(new File(workingDir, submoduleDirectoryName), "file-").get(0);
    FileUtils.writeStringToFile(fileInSubmodule, "Some other new content.");
    /* Commit a change to the file on the repo. */
    List<Modification> modifications = submoduleRepos.modifyOneFileInSubmoduleAndUpdateMainRepo(remoteSubmoduleLocation, submoduleDirectoryName, fileInSubmodule.getName(), "NEW CONTENT OF FILE");
    updateTo(material, new RevisionContext(new StringRevision(modifications.get(0).getRevision())), JobResult.Passed);
    assertThat(FileUtils.readFileToString(fileInSubmodule), Matchers.is("NEW CONTENT OF FILE"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) 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) File(java.io.File) Test(org.junit.Test)

Example 7 with Modification

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

the class ModificationBuildCauseTest method shouldReturnBuildCauseMessage.

@Test
public void shouldReturnBuildCauseMessage() {
    MaterialRevisions revisions = new MaterialRevisions();
    Modification modification = new Modification(new Date(), "pipelineName/123/stageName/1", "MOCK_LABEL-12", null);
    revisions.addRevision(new DependencyMaterial(new CaseInsensitiveString("cruise"), new CaseInsensitiveString("dev")), modification);
    BuildCause modificationBuildCause = BuildCause.createWithModifications(revisions, "");
    String message = modificationBuildCause.getBuildCauseMessage();
    assertThat(message, containsString("triggered by pipelineName/123/stageName/1"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.Test)

Example 8 with Modification

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

the class ModificationBuildCauseTest method shouldGetBuildCausedByIfIsDenpendencyMaterial.

@Test
public void shouldGetBuildCausedByIfIsDenpendencyMaterial() throws Exception {
    MaterialRevisions revisions = new MaterialRevisions();
    Modification modification = new Modification(new Date(), "pipelineName/10/stageName/1", "MOCK_LABEL-12", null);
    revisions.addRevision(new DependencyMaterial(new CaseInsensitiveString("cruise"), new CaseInsensitiveString("dev")), modification);
    assertThat(BuildCause.createWithModifications(revisions, "").getBuildCauseMessage(), is("triggered by pipelineName/10/stageName/1"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 9 with Modification

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

the class GitCommandTest method shouldReturnNothingForModificationsSinceIfARebasedCommitSHAIsPassed.

@Test
public void shouldReturnNothingForModificationsSinceIfARebasedCommitSHAIsPassed() 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, "master", false, new HashMap<>(), null);
    Modification modification = remoteRepo.addFileAndAmend("foo", "amendedCommit").get(0);
    assertThat(command.modificationsSince(new StringRevision(modification.getRevision())).isEmpty(), is(true));
}
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 10 with Modification

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

the class GitCommandTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.

@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos();
    String submoduleDirectoryName = "local-submodule";
    File cloneDirectory = createTempWorkingDirectory();
    File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
    /* Simulate an agent checkout of code. */
    GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
    clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
    /* Simulate a local modification of file inside submodule, on agent side. */
    File fileInSubmodule = allFilesIn(new File(cloneDirectory, submoduleDirectoryName), "file-").get(0);
    FileUtils.writeStringToFile(fileInSubmodule, "Some other new content.");
    /* Commit a change to the file on the repo. */
    List<Modification> modifications = submoduleRepos.modifyOneFileInSubmoduleAndUpdateMainRepo(remoteSubmoduleLocation, submoduleDirectoryName, fileInSubmodule.getName(), "NEW CONTENT OF FILE");
    /* Simulate start of a new build on agent. */
    clonedCopy.fetch(outputStreamConsumer);
    clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision(modifications.get(0).getRevision()));
    assertThat(FileUtils.readFileToString(fileInSubmodule), is("NEW CONTENT OF FILE"));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitSubmoduleRepos(com.thoughtworks.go.helper.GitSubmoduleRepos) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ModifiedFile(com.thoughtworks.go.domain.materials.ModifiedFile) File(java.io.File)

Aggregations

Modification (com.thoughtworks.go.domain.materials.Modification)242 Test (org.junit.Test)164 Date (java.util.Date)78 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)68 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)55 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)41 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)40 ArrayList (java.util.ArrayList)34 File (java.io.File)25 Modifications (com.thoughtworks.go.domain.materials.Modifications)21 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)20 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)20 Material (com.thoughtworks.go.domain.materials.Material)20 HashMap (java.util.HashMap)18 Username (com.thoughtworks.go.server.domain.Username)17 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)15 Pipeline (com.thoughtworks.go.domain.Pipeline)14 Stage (com.thoughtworks.go.domain.Stage)14 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)14 StringContains.containsString (org.hamcrest.core.StringContains.containsString)14