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"));
}
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");
}
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"));
}
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");
}
Aggregations