Search in sources :

Example 16 with GitRepository

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());
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) GitRepository(com.google.copybara.git.GitRepository) ValidationException(com.google.copybara.exception.ValidationException) Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 17 with GitRepository

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());
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) GitRepository(com.google.copybara.git.GitRepository) Migration(com.google.copybara.config.Migration)

Aggregations

GitRepository (com.google.copybara.git.GitRepository)17 Test (org.junit.Test)12 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)10 Path (java.nio.file.Path)10 Migration (com.google.copybara.config.Migration)6 GitRevision (com.google.copybara.git.GitRevision)5 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)5 LowLevelHttpRequest (com.google.api.client.http.LowLevelHttpRequest)3 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)3 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)3 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)3 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)3 ValidationException (com.google.copybara.exception.ValidationException)3 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)3 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)2 IOException (java.io.IOException)2 Predicate (java.util.function.Predicate)2 ChangeRejectedException (com.google.copybara.exception.ChangeRejectedException)1 GerritOptions (com.google.copybara.git.GerritOptions)1 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)1