use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitMaterialUpdaterTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.
@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
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.", UTF_8);
/* 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, UTF_8), Matchers.is("NEW CONTENT OF FILE"));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitMaterialUpdaterTest method shouldAllowSubmoduleUrlstoChange.
@Test
public void shouldAllowSubmoduleUrlstoChange() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
String submoduleDirectoryName = "local-submodule";
submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName);
updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
assertThat(console.output(), containsString("Synchronizing submodule url for 'local-submodule'"));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitMaterialUpdaterTest method shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating.
@Test
public void shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
String submoduleDirectoryName = "local-submodule";
submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
GitMaterial material = new GitMaterial(submoduleRepos.projectRepositoryUrl(), true);
updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
File unversionedFile = new File(new File(workingDir, submoduleDirectoryName), "unversioned_file.txt");
FileUtils.writeStringToFile(unversionedFile, "this is an unversioned file. lets see you deleting me.. come on.. I dare you!!!!", UTF_8);
updateTo(material, new RevisionContext(new StringRevision("origin/HEAD")), JobResult.Passed);
assertThat(unversionedFile.exists(), Matchers.is(false));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitMaterialUpdaterTest method shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo.
@Test
public void shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
submoduleRepos.addSubmodule(SUBMODULE, "sub1");
GitMaterial gitMaterial = new GitMaterial(submoduleRepos.mainRepo().getUrl(), true);
StringRevision revision = new StringRevision("origin/master");
updateTo(gitMaterial, new RevisionContext(revision), JobResult.Passed);
assertThat(new File(workingDir, "sub1"), exists());
submoduleRepos.removeSubmodule("sub1");
updateTo(gitMaterial, new RevisionContext(revision), JobResult.Passed);
assertThat(new File(workingDir, "sub1"), not(exists()));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos 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()))));
}
}
Aggregations