Search in sources :

Example 11 with Author

use of com.google.copybara.authoring.Author 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();
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Author(com.google.copybara.authoring.Author) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry)

Example 12 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class HgDestinationTest method testWrite.

@Test
public void testWrite() throws Exception {
    Files.write(workdir.resolve("file.txt"), "first write".getBytes(UTF_8));
    Files.write(workdir.resolve("test.txt"), "test".getBytes(UTF_8));
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1496333940000L), ZoneId.of("-04:00"));
    DummyRevision originRef = new DummyRevision("origin_ref").withAuthor(new Author("Copy Bara", "copy@bara.com")).withTimestamp(zonedDateTime);
    TransformResult result = TransformResults.of(workdir, originRef);
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
    ImmutableList<HgLogEntry> commits = remoteRepo.log().run();
    assertThat(commits).hasSize(2);
    assertThat(commits.get(0).getDescription()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref");
    assertThat(commits).hasSize(2);
    assertThat(commits.get(0).getZonedDate()).isEqualTo(zonedDateTime);
    assertThat(commits.get(0).getFiles()).hasSize(1);
    assertThat(commits.get(0).getFiles().get(0)).isEqualTo("test.txt");
    assertThat(commits.get(1).getFiles()).hasSize(1);
    assertThat(commits.get(1).getFiles().get(0)).isEqualTo("file.txt");
}
Also used : TransformResult(com.google.copybara.TransformResult) ZonedDateTime(java.time.ZonedDateTime) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 13 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class RemoteArchiveOriginTest method testZipFileUnpacked.

@Test
public void testZipFileUnpacked() throws Exception {
    when(transport.open(any())).thenReturn(new ByteArrayInputStream(BaseEncoding.base64().decode(CAPUTRED_HELLO_WORLD_ZIP_FILE)));
    RemoteArchiveOrigin underTest = new RemoteArchiveOrigin("zip", Author.parse("Copybara <noreply@copybara.io>"), "a message", transport, profiler, remoteFileOptions);
    underTest.resolve("foo");
    Reader<RemoteArchiveRevision> reader = underTest.newReader(Glob.ALL_FILES, new Authoring(new Author("foo", "default@example.com"), AuthoringMappingMode.PASS_THRU, ImmutableSet.of()));
    RemoteArchiveRevision revision = underTest.resolve("https://foo.zip");
    reader.checkout(revision, workdir);
    assertThatPath(workdir).containsFile("test.txt", "hello world\n");
}
Also used : Authoring(com.google.copybara.authoring.Authoring) ByteArrayInputStream(java.io.ByteArrayInputStream) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 14 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class RemoteArchiveOriginTest method testZipFileEmptyGlob.

@Test
public void testZipFileEmptyGlob() throws Exception {
    when(transport.open(any())).thenReturn(new ByteArrayInputStream(BaseEncoding.base64().decode(CAPUTRED_HELLO_WORLD_ZIP_FILE)));
    RemoteArchiveOrigin underTest = new RemoteArchiveOrigin("zip", Author.parse("Copybara <noreply@copybara.io>"), "a message", transport, profiler, remoteFileOptions);
    underTest.resolve("foo");
    Reader<RemoteArchiveRevision> reader = underTest.newReader(Glob.createGlob(ImmutableList.of("no match"), ImmutableList.of("**")), new Authoring(new Author("foo", "default@example.com"), AuthoringMappingMode.PASS_THRU, ImmutableSet.of()));
    RemoteArchiveRevision revision = underTest.resolve("https://foo.zip");
    reader.checkout(revision, workdir);
    assertThatPath(workdir).containsNoFiles("test.txt", "hello world\n");
}
Also used : Authoring(com.google.copybara.authoring.Authoring) ByteArrayInputStream(java.io.ByteArrayInputStream) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Example 15 with Author

use of com.google.copybara.authoring.Author in project copybara by google.

the class DummyOriginTest method testCanSpecifyMessage.

@Test
public void testCanSpecifyMessage() throws Exception {
    DummyOrigin origin = new DummyOrigin().addSimpleChange(/*timestamp*/
    4242, "foo msg");
    Authoring authoring = new Authoring(new Author("foo", "default.example.com"), AuthoringMappingMode.OVERWRITE, ImmutableSet.of());
    Reader<DummyRevision> reader = origin.newReader(Glob.ALL_FILES, authoring);
    ImmutableList<Change<DummyRevision>> changes = reader.changes(/*fromRef*/
    null, /*toRef*/
    origin.resolve("0")).getChanges();
    assertThat(changes).hasSize(1);
    assertThat(changes.get(0).getMessage()).isEqualTo("foo msg");
}
Also used : Authoring(com.google.copybara.authoring.Authoring) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) Test(org.junit.Test)

Aggregations

Author (com.google.copybara.authoring.Author)47 Test (org.junit.Test)36 DummyRevision (com.google.copybara.testing.DummyRevision)12 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)12 Change (com.google.copybara.Change)10 Changes (com.google.copybara.Changes)9 Authoring (com.google.copybara.authoring.Authoring)8 DestinationEffect (com.google.copybara.DestinationEffect)7 WriterContext (com.google.copybara.WriterContext)6 ZonedDateTime (java.time.ZonedDateTime)6 TransformResult (com.google.copybara.TransformResult)5 TransformWork (com.google.copybara.TransformWork)5 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ImmutableList (com.google.common.collect.ImmutableList)3 Transformation (com.google.copybara.Transformation)3 InvalidAuthorException (com.google.copybara.authoring.InvalidAuthorException)3 ValidationException (com.google.copybara.exception.ValidationException)3 DummyChecker (com.google.copybara.testing.DummyChecker)3 ImmutableMap (com.google.common.collect.ImmutableMap)2