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"));
}
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"));
}
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"));
}
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));
}
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"));
}
Aggregations