Search in sources :

Example 26 with GitLogEntry

use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.

the class GitDestinationTest method testCheckerDescription_label_leak_is_fine.

@Test
public void testCheckerDescription_label_leak_is_fine() throws Exception {
    runDescriptionChecker(new DummyChecker(ImmutableSet.of(DummyOrigin.LABEL_NAME)));
    ImmutableList<GitLogEntry> head = repo().log(primaryBranch).withLimit(1).run();
    assertThat(head).isNotEmpty();
    assertThat(head.get(0).getBody()).isEqualTo("This is BAD\n\nDummyOrigin-RevId: ref2\n");
    assertThat(head.get(0).getAuthor()).isEqualTo(new Author("Dont", "rewri@te.me"));
}
Also used : Author(com.google.copybara.authoring.Author) DummyChecker(com.google.copybara.testing.DummyChecker) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 27 with GitLogEntry

use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.

the class GitHubPrDestinationTest method checkWrite.

private void checkWrite(Revision revision) throws ValidationException, RepoException, IOException {
    mockNoPullRequestsGet("feature");
    gitUtil.mockApi("POST", "https://api.github.com/repos/foo/pulls", mockResponseAndValidateRequest("{\n" + "  \"id\": 1,\n" + "  \"number\": 12345,\n" + "  \"state\": \"open\",\n" + "  \"title\": \"test summary\",\n" + "  \"body\": \"test summary\"\n" + "}", MockRequestAssertion.equals("{\"base\":\"main\",\"body\":\"test summary\\n\",\"head\":\"" + "feature" + "\",\"title\":\"test summary\"}")));
    GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + "    url = 'https://github.com/foo'," + "    destination_ref = 'main'" + ")");
    Writer<GitRevision> writer = d.newWriter(new WriterContext("piper_to_github_pr", "TEST", false, revision, Glob.ALL_FILES.roots()));
    GitRepository remote = gitUtil.mockRemoteRepo("github.com/foo");
    addFiles(remote, null, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").buildOrThrow());
    writeFile(this.workdir, "test.txt", "some content");
    writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), Glob.ALL_FILES, console);
    writeFile(this.workdir, "test.txt", "other content");
    writer.write(TransformResults.of(this.workdir, new DummyRevision("two")), Glob.ALL_FILES, console);
    writeFile(this.workdir, "test.txt", "and content");
    writer.write(TransformResults.of(this.workdir, new DummyRevision("three")), Glob.ALL_FILES, console);
    console.assertThat().timesInLog(1, MessageType.INFO, "Pull Request https://github.com/foo/pull/12345 created using branch 'feature'.");
    assertThat(remote.refExists("feature")).isTrue();
    assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: one\n", "test summary\n" + "\n" + "DummyOrigin-RevId: two\n", "test summary\n" + "\n" + "DummyOrigin-RevId: three\n");
    // If we don't keep writer state (same as a new migration). We do a rebase of
    // all the changes.
    writer = d.newWriter(new WriterContext("piper_to_github_pr", "TEST", false, revision, Glob.ALL_FILES.roots()));
    writeFile(this.workdir, "test.txt", "and content");
    gitUtil.mockApi("GET", getPullRequestsUrl("feature"), mockResponse("" + "[{\n" + "  \"id\": 1,\n" + "  \"number\": 12345,\n" + "  \"state\": \"open\",\n" + "  \"title\": \"test summary\",\n" + "  \"body\": \"test summary\"," + "  \"head\": { \"ref\": \"feature\"}," + "  \"base\": { \"ref\": \"feature\"}" + "}]"));
    writer.write(TransformResults.of(this.workdir, new DummyRevision("four")), Glob.ALL_FILES, console);
    assertThat(Iterables.transform(remote.log("feature").run(), GitLogEntry::getBody)).containsExactly("first change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: four\n");
}
Also used : WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry)

Example 28 with GitLogEntry

use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.

the class GitRepositoryTest method testLogContainingEquals.

@Test
public void testLogContainingEquals() throws Exception {
    Files.write(workdir.resolve("foo.txt"), "foo".getBytes(UTF_8));
    repository.add().files("foo.txt").run();
    ZonedDateTime date = ZonedDateTime.now(ZoneId.of("-07:00")).truncatedTo(ChronoUnit.SECONDS);
    repository.commit("= Foo = <bar@bara.com>", date, "adding foo");
    ImmutableList<GitLogEntry> entries = repository.log(defaultBranch).run();
    assertThat(entries.get(0).getAuthor()).isEqualTo(new Author("= Foo =", "bar@bara.com"));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Author(com.google.copybara.authoring.Author) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 29 with GitLogEntry

use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.

the class GitRepositoryTest method testUnicodeFilename.

@Test
public void testUnicodeFilename() throws RepoException, IOException {
    writeFile(workdir, "unrelated", "unrelated");
    repository.add().files("unrelated").run();
    repository.simpleCommand("commit", "-a", "-m", "unrelated change");
    writeFile(workdir, "test/hello_\360\237\214\220.isolate", "hi");
    writeFile(workdir, "test/foo", "bye");
    repository.add().files("test/hello_\360\237\214\220.isolate").run();
    repository.add().files("test/foo").run();
    // 
    repository.simpleCommand("commit", "-a", "-m", "message");
    GitLogEntry entry = repository.log("HEAD").includeFiles(true).withLimit(2).run().get(0);
    assertThat(entry.getFiles()).containsExactly("test/hello_\360\237\214\220.isolate", "test/foo");
}
Also used : GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Aggregations

GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)29 Test (org.junit.Test)19 Path (java.nio.file.Path)12 DummyRevision (com.google.copybara.testing.DummyRevision)9 ImmutableList (com.google.common.collect.ImmutableList)6 WriterContext (com.google.copybara.WriterContext)6 Iterables (com.google.common.collect.Iterables)5 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)5 RepoException (com.google.copybara.exception.RepoException)5 ValidationException (com.google.copybara.exception.ValidationException)5 Glob (com.google.copybara.util.Glob)5 IOException (java.io.IOException)5 Optional (java.util.Optional)5 Joiner (com.google.common.base.Joiner)4 DestinationStatus (com.google.copybara.Destination.DestinationStatus)4 Author (com.google.copybara.authoring.Author)4 Lists (com.google.common.collect.Lists)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)3 Writer (com.google.copybara.Destination.Writer)3