use of com.google.copybara.testing.FileSubjects.assertThatPath in project copybara by google.
the class WorkflowTest method testToFolderFlag.
@Test
public void testToFolderFlag() throws Exception {
Path originPath = Files.createTempDirectory("origin");
Path destinationPath = Files.createTempDirectory("destination");
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
GitRepository destination = GitRepository.newRepo(/*verbose*/
true, destinationPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(" + " name = '" + "default" + "'," + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = git.destination(" + " url = 'file://" + destination.getWorkTree() + "',\n" + " ),\n" + " authoring = " + authoring + "," + " mode = '" + WorkflowMode.ITERATIVE + "'," + ")\n";
Files.write(originPath.resolve("foo.txt"), "change".getBytes(UTF_8));
origin.add().files("foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "not important");
String firstCommit = origin.parseRef("HEAD");
options.workflowOptions.toFolder = true;
options.general.squash = true;
Path localFolder = Files.createTempDirectory("local_folder");
options.folderDestination.localFolder = localFolder.toString();
options.setWorkdirToRealTempDir();
// Pass custom HOME directory so that we run an hermetic test and we
// can add custom configuration to $HOME/.gitconfig.
options.setEnvironment(GitTestUtil.getGitEnv().getEnvironment());
options.setHomeDir(Files.createTempDirectory("home").toString());
options.gitDestination.committerName = "Foo";
options.gitDestination.committerEmail = "foo@foo.com";
options.workflowOptions.checkLastRevState = true;
loadConfig(config).getMigration("default").run(Files.createTempDirectory("checkout"), ImmutableList.of());
FileSubjects.assertThatPath(localFolder).containsFile("foo.txt", "change").containsNoMoreFiles();
assertThrows(CannotResolveRevisionException.class, () -> destination.resolveReference("HEAD"));
}
Aggregations