use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitMaterialTest method shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo.
@Test
public void shouldRemoveSubmoduleFolderFromWorkingDirWhenSubmoduleIsRemovedFromRepo() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
submoduleRepos.addSubmodule(SUBMODULE, "sub1");
GitMaterial gitMaterial = new GitMaterial(submoduleRepos.mainRepo().getUrl());
StringRevision revision = new StringRevision("origin/master");
gitMaterial.updateTo(outputStreamConsumer, workingDir, new RevisionContext(revision), new TestSubprocessExecutionContext());
assertThat(new File(workingDir, "sub1"), exists());
submoduleRepos.removeSubmodule("sub1");
outputStreamConsumer = inMemoryConsumer();
gitMaterial.updateTo(outputStreamConsumer, workingDir, new RevisionContext(revision), new TestSubprocessExecutionContext());
assertThat(new File(workingDir, "sub1"), not(exists()));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class MaterialDatabaseGitWithSubmodulesUpdaterTest method repo.
protected TestRepo repo() throws Exception {
GitSubmoduleRepos testRepoWithExternal = new GitSubmoduleRepos(temporaryFolder);
testRepoWithExternal.addSubmodule("submodule-1", "sub1");
return testRepoWithExternal;
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitCommandTest method shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating.
@Test
public void shouldCleanUnversionedFilesInsideSubmodulesBeforeUpdating() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
String submoduleDirectoryName = "local-submodule";
submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
File cloneDirectory = createTempWorkingDirectory();
GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
// Clone repository without submodules
clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
// Pull submodules to working copy - Pipeline counter 1
clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
File unversionedFile = new File(new File(cloneDirectory, submoduleDirectoryName), "unversioned_file.txt");
FileUtils.writeStringToFile(unversionedFile, "this is an unversioned file. lets see you deleting me.. come on.. I dare you!!!!", UTF_8);
// Should clean unversioned file on next fetch - Pipeline counter 2
clonedCopy.resetWorkingDir(outputStreamConsumer, new StringRevision("HEAD"));
assertThat(unversionedFile.exists(), is(false));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitCommandTest method shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating.
@Test
public void shouldRemoveChangesToModifiedFilesInsideSubmodulesBeforeUpdating() throws Exception {
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
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.", UTF_8);
/* 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, UTF_8), is("NEW CONTENT OF FILE"));
}
use of com.thoughtworks.go.helper.GitSubmoduleRepos in project gocd by gocd.
the class GitCommandTest method shouldAllowSubmoduleUrlstoChange.
@Test
public void shouldAllowSubmoduleUrlstoChange() throws Exception {
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
String submoduleDirectoryName = "local-submodule";
File cloneDirectory = createTempWorkingDirectory();
File remoteSubmoduleLocation = submoduleRepos.addSubmodule(SUBMODULE, submoduleDirectoryName);
GitCommand clonedCopy = new GitCommand(null, cloneDirectory, GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
clonedCopy.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
clonedCopy.fetchAndResetToHead(outputStreamConsumer);
submoduleRepos.changeSubmoduleUrl(submoduleDirectoryName);
clonedCopy.fetchAndResetToHead(outputStreamConsumer);
}
Aggregations