use of com.thoughtworks.go.util.command.InMemoryStreamConsumer 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.util.command.InMemoryStreamConsumer 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);
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class GitCommandTest method shouldNotFailIfUnableToRemoveSubmoduleEntryFromConfig.
@Test
public void shouldNotFailIfUnableToRemoveSubmoduleEntryFromConfig() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
submoduleRepos.addSubmodule(SUBMODULE, "sub1");
GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null);
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
gitWithSubmodule.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
gitWithSubmodule.fetchAndResetToHead(outputStreamConsumer);
gitWithSubmodule.updateSubmoduleWithInit(outputStreamConsumer);
List<String> folders = gitWithSubmodule.submoduleFolders();
assertThat(folders.size(), is(1));
assertThat(folders.get(0), is("sub1"));
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class GitCommandTest method shouldBombForFetchFailure.
@Test
public void shouldBombForFetchFailure() throws IOException {
executeOnGitRepo("git", "remote", "rm", "origin");
executeOnGitRepo("git", "remote", "add", "origin", "git://user:secret@foo.bar/baz");
try {
InMemoryStreamConsumer output = new InMemoryStreamConsumer();
git.fetch(output);
fail("should have failed for non 0 return code. Git output was:\n " + output.getAllOutput());
} catch (Exception e) {
assertThat(e.getMessage(), is("git fetch failed for [git://user:******@foo.bar/baz]"));
}
}
use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.
the class GitCommandTest method shouldNotThrowErrorWhenConfigRemoveSectionFails.
@Test
public void shouldNotThrowErrorWhenConfigRemoveSectionFails() throws Exception {
GitSubmoduleRepos submoduleRepos = new GitSubmoduleRepos(temporaryFolder);
submoduleRepos.addSubmodule(SUBMODULE, "sub1");
GitCommand gitWithSubmodule = new GitCommand(null, createTempWorkingDirectory(), GitMaterialConfig.DEFAULT_BRANCH, false, new HashMap<>(), null) {
// hack to reproduce synchronization issue
@Override
public Map<String, String> submoduleUrls() {
return Collections.singletonMap("submodule", "submodule");
}
};
InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
gitWithSubmodule.clone(outputStreamConsumer, submoduleRepos.mainRepo().getUrl());
gitWithSubmodule.updateSubmoduleWithInit(outputStreamConsumer);
}
Aggregations