use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method reversibleCheckFiles.
@Test
public void reversibleCheckFiles() throws Exception {
Path someRoot = Files.createTempDirectory("someRoot");
Path originPath = someRoot.resolve("origin");
Files.createDirectories(originPath);
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(\n" + " name = 'default',\n" + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = testing.destination(),\n" + " authoring = " + authoring + ",\n" + " reversible_check = True,\n" + " reversible_check_ignore_files = glob([\"to_ignore/**\"]," + " exclude = [\"to_ignore/exclude\"]),\n" + " mode = '" + WorkflowMode.SQUASH + "',\n" + " transformations = [" + " core.replace(before = 'aa', after = 'bb')" + " ]" + ")\n";
Migration workflow = loadConfig(config).getMigration("default");
GitTestUtil.writeFile(originPath, "test", "aabb");
GitTestUtil.writeFile(originPath, "to_ignore/test", "aabb");
GitTestUtil.writeFile(originPath, "to_ignore/exclude", "aabb");
origin.add().all().run();
origin.simpleCommand("commit", "-m", "change");
try {
workflow.run(Files.createDirectory(someRoot.resolve("run1")), ImmutableList.of());
fail();
} catch (ValidationException e) {
assertThat(e).hasMessageThat().contains("is not reversible");
String msg = console().getMessages().stream().filter(m -> m.getType() == MessageType.ERROR && m.getText().contains("Non reversible")).findFirst().get().getText();
assertThat(msg).contains("--- a/origin/test");
assertThat(msg).doesNotContain("--- a/origin/to_ignore/test");
assertThat(msg).contains("--- a/origin/to_ignore/exclude");
}
// Now lets fix the only file that we check in reversible check:
GitTestUtil.writeFile(originPath, "test", "aa");
GitTestUtil.writeFile(originPath, "to_ignore/exclude", "aa");
origin.add().all().run();
origin.simpleCommand("commit", "-m", "change 2");
workflow.run(Files.createDirectory(someRoot.resolve("run2")), ImmutableList.of());
}
use of com.google.copybara.git.GitRepository in project copybara by google.
the class WorkflowTest method runGitDescribeVersionSemanticsForFilteredChanges.
private void runGitDescribeVersionSemanticsForFilteredChanges(String mode) throws IOException, RepoException, ValidationException {
Path someRoot = Files.createTempDirectory("someRoot");
Path originPath = someRoot.resolve("origin");
Files.createDirectories(originPath);
GitRepository origin = GitRepository.newRepo(/*verbose*/
true, originPath, getGitEnv()).init();
String primaryBranch = origin.getPrimaryBranch();
String config = "core.workflow(\n" + " name = 'default',\n" + String.format(" origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + " destination = testing.destination(),\n" + " authoring = " + authoring + ",\n" + " origin_files = glob(['included/**']),\n" + " mode = '" + mode + "',\n" + " transformations = [" + "metadata.add_header('Resolved revision is ${GIT_DESCRIBE_REQUESTED_VERSION}" + " and change revision is ${GIT_DESCRIBE_CHANGE_VERSION}')]" + ")\n";
GitTestUtil.writeFile(originPath, "initial.txt", "initial");
origin.add().files("initial.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "Initial");
origin.simpleCommand("tag", "-m", "this is a tag!", "0.1");
options.setLastRevision(origin.parseRef("HEAD"));
Migration workflow = loadConfig(config).getMigration("default");
GitTestUtil.writeFile(originPath, "included/foo.txt", "a");
origin.add().files("included/foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "one");
GitTestUtil.writeFile(originPath, "included/foo.txt", "b");
origin.add().files("included/foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "two");
GitTestUtil.writeFile(originPath, "excluded/foo.txt", "c");
origin.add().files("excluded/foo.txt").run();
origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "three");
workflow.run(workdir, ImmutableList.of());
}
Aggregations