use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitHubPrDestinationTest method testWriteNomain.
@Test
public void testWriteNomain() throws ValidationException, IOException, RepoException {
GitHubPrDestination d = skylark.eval("r", "r = git.github_pr_destination(" + " url = 'https://github.com/foo'," + " destination_ref = 'other'," + ")");
DummyRevision dummyRevision = new DummyRevision("dummyReference", "feature");
WriterContext writerContext = new WriterContext("piper_to_github_pr", "TEST", false, dummyRevision, Glob.ALL_FILES.roots());
String branchName = Identity.computeIdentity("OriginGroupIdentity", dummyRevision.contextReference(), writerContext.getWorkflowName(), "copy.bara.sky", writerContext.getWorkflowIdentityUser());
mockNoPullRequestsGet(branchName);
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\"" + "}", MockRequestAssertion.equals("{\"base\":\"other\",\"body\":\"test summary\\n\",\"head\":\"" + branchName + "\",\"title\":\"test summary\"}")));
Writer<GitRevision> writer = d.newWriter(writerContext);
GitRepository remote = gitUtil.mockRemoteRepo("github.com/foo");
addFiles(remote, "main", "first change", ImmutableMap.<String, String>builder().put("foo.txt", "").buildOrThrow());
addFiles(remote, "other", "second change", ImmutableMap.<String, String>builder().put("foo.txt", "test").buildOrThrow());
writeFile(this.workdir, "test.txt", "some content");
writer.write(TransformResults.of(this.workdir, new DummyRevision("one")), Glob.ALL_FILES, console);
assertThat(remote.refExists(branchName)).isTrue();
assertThat(Iterables.transform(remote.log(branchName).run(), GitLogEntry::getBody)).containsExactly("first change\n", "second change\n", "test summary\n" + "\n" + "DummyOrigin-RevId: one\n");
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitMirrorTest method testMerge.
@Test
public void testMerge() throws Exception {
Migration mirror = mergeInit();
GitLogEntry destChange = repoChange(destRepo, "some_file", "Content", "destination only");
GitLogEntry originChange = repoChange(originRepo, "some_other_file", "Content", "new change");
mirror.run(workdir, ImmutableList.of());
GitLogEntry merge = lastChange(destRepo, primaryBranch);
// It is a merge
assertThat(merge.getParents()).containsExactly(destChange.getCommit(), originChange.getCommit());
// OSS branch is updated with origin version.
assertThat(lastChange(destRepo, "oss").getCommit()).isEqualTo(originChange.getCommit());
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitMirrorTest method testMergeConflict.
@Test
public void testMergeConflict() throws Exception {
Migration mirror = mergeInit();
GitLogEntry destChange = repoChange(destRepo, "some_file", "Hello", "destination only");
GitLogEntry originChange = repoChange(originRepo, "some_file", "Bye", "new change");
assertThat((assertThrows(ValidationException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
mirror.run(workdir, ImmutableList.of());
}
}))).hasMessageThat().contains("Conflict merging refs/heads/" + primaryBranch);
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitRepositoryTest method checkLog.
private void checkLog(boolean body, boolean includeFiles) throws IOException, RepoException, ValidationException {
workdir = Files.createTempDirectory("workdir");
this.repository = GitRepository.newBareRepo(Files.createTempDirectory("gitdir"), getGitEnv(), /*verbose=*/
true, DEFAULT_TIMEOUT, /*noVerify=*/
false).withWorkTree(workdir).init();
Files.write(workdir.resolve("foo.txt"), "foo fooo fooo".getBytes(UTF_8));
repository.add().files("foo.txt").run();
ZonedDateTime date = ZonedDateTime.now(ZoneId.of("-07:00")).truncatedTo(ChronoUnit.SECONDS);
ZonedDateTime date2 = date.plus(1, ChronoUnit.SECONDS).withZoneSameInstant(ZoneId.of("-05:00"));
repository.commit("Foo <foo@bara.com>", date, "message");
// Test rename to check that we use --name-only with --no-renames
Files.move(workdir.resolve("foo.txt"), workdir.resolve("bar.txt"));
Files.write(workdir.resolve("baz.txt"), "baz baz baz".getBytes(UTF_8));
repository.add().all().run();
repository.commit("Bar <bar@bara.com>", date2, "message\n\nand\nparagraph");
ImmutableList<GitLogEntry> entries = repository.log(defaultBranch).includeBody(body).includeFiles(includeFiles).run();
assertThat(entries.size()).isEqualTo(2);
assertThat(entries.get(0).getBody()).isEqualTo(body ? "message\n\nand\nparagraph\n" : null);
assertThat(entries.get(1).getBody()).isEqualTo(body ? "message\n" : null);
assertThat(entries.get(0).getAuthor()).isEqualTo(new Author("Bar", "bar@bara.com"));
assertThat(entries.get(0).getCommitter()).isEqualTo(COMMITER);
assertThat(entries.get(0).getAuthorDate()).isEqualTo(date2);
assertThat(entries.get(1).getAuthor()).isEqualTo(new Author("FOO", "foo@bara.com"));
assertThat(entries.get(1).getCommitter()).isEqualTo(COMMITER);
assertThat(entries.get(1).getAuthorDate()).isEqualTo(date);
assertThat(entries.get(0).getParents()).containsExactly(entries.get(1).getCommit());
assertThat(entries.get(1).getParents()).isEmpty();
assertThat(repository.simpleCommand("cat-file", "-t", entries.get(0).getTree()).getStdout().trim()).isEqualTo("tree");
if (includeFiles) {
assertThat(entries.get(0).getFiles()).containsExactly("foo.txt", "bar.txt", "baz.txt");
assertThat(entries.get(1).getFiles()).containsExactly("foo.txt");
} else {
assertThat(entries.get(0).getFiles()).isNull();
assertThat(entries.get(1).getFiles()).isNull();
}
}
use of com.google.copybara.git.GitRepository.GitLogEntry in project copybara by google.
the class GitRepositoryTest method testBadCommitInLog.
@Test
public void testBadCommitInLog() throws RepoException, IOException {
Files.write(workdir.resolve("foo.txt"), new byte[] {});
repository.add().files("foo.txt").run();
//
repository.simpleCommand("commit", "foo.txt", "-m", "message");
GitLogEntry entry = Iterables.getOnlyElement(repository.log("HEAD").withLimit(1).run());
String badCommit = "tree " + entry.getTree() + "\n" + "parent " + entry.getCommit().getSha1() + "\n" + "author Some User <example@example.com> 1528942829 --400\n" + "committer Some User <example@example.com> 1528942829 --400\n" + "\n" + "Allow to check and resolve symlinks";
Files.write(workdir.resolve("commit"), badCommit.getBytes(UTF_8));
String commitSha1 = repository.simpleCommand("hash-object", "-w", "-t", "commit", "--", workdir.resolve("commit").toAbsolutePath().toString()).getStdout().trim();
entry = Iterables.getOnlyElement(repository.log(commitSha1).withLimit(1).run());
ZonedDateTime epoch = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC);
assertThat(entry.getAuthorDate()).isEquivalentAccordingToCompareTo(epoch);
assertThat(entry.getCommitDate()).isEquivalentAccordingToCompareTo(epoch);
}
Aggregations