Search in sources :

Example 1 with HgLogEntry

use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.

the class ChangeReader method parseChanges.

private ImmutableList<Change<HgRevision>> parseChanges(ImmutableList<HgLogEntry> logEntries) throws RepoException {
    ImmutableList.Builder<Change<HgRevision>> result = ImmutableList.builder();
    for (HgLogEntry entry : logEntries) {
        HgRevision rev = new HgRevision(entry.getGlobalId());
        if (NULL_GLOBAL_ID.equals(rev.getGlobalId())) {
            continue;
        }
        Author user;
        try {
            user = AuthorParser.parse(entry.getUser());
        } catch (InvalidAuthorException e) {
            console.warn(String.format("Cannot parse commit user and email: %s", e.getMessage()));
            user = authoring.orElseThrow(() -> new RepoException("No default author provided.")).getDefaultAuthor();
        }
        ImmutableList<HgRevision> parents = entry.getParents().stream().map(HgRevision::new).collect(ImmutableList.toImmutableList());
        result.add(new Change<>(rev, user, entry.getDescription(), entry.getZonedDate(), ChangeMessage.parseAllAsLabels(entry.getDescription()).labelsAsMultimap(), ImmutableSet.copyOf(entry.getFiles()), parents.size() > 1, parents));
    }
    return result.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change) RepoException(com.google.copybara.exception.RepoException) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) InvalidAuthorException(com.google.copybara.authoring.InvalidAuthorException)

Example 2 with HgLogEntry

use of com.google.copybara.hg.HgRepository.HgLogEntry 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 3 with HgLogEntry

use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.

the class HgRepositoryTest method testLogTwoParents.

@Test
public void testLogTwoParents() throws Exception {
    Path newFile = addAndCommitFile("foo");
    Path remoteDir = Files.createTempDirectory("remotedir");
    HgRepository remoteRepo = new HgRepository(remoteDir, /*verbose*/
    false, CommandRunner.DEFAULT_TIMEOUT);
    remoteRepo.init();
    Path newFile2 = Files.createTempFile(remoteDir, "foo", ".txt");
    String fileName2 = newFile2.toString();
    Files.write(remoteDir.resolve(fileName2), "hello".getBytes(UTF_8));
    remoteRepo.hg(remoteDir, "add", fileName2);
    remoteRepo.hg(remoteDir, "commit", "-m", "hello");
    repository.pullAll(remoteDir.toString());
    repository.hg(workDir, "merge");
    Files.write(workDir.resolve(newFile.toString()), "hello".getBytes(UTF_8));
    repository.hg(workDir, "commit", "-m", "merge");
    ImmutableList<HgLogEntry> commits = repository.log().run();
    assertThat(commits.get(0).getParents()).hasSize(2);
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 4 with HgLogEntry

use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.

the class HgRepositoryTest method testLog.

@Test
public void testLog() throws Exception {
    String user = "Copy Bara <copy@bara.com>";
    ZonedDateTime date = ZonedDateTime.now(ZoneId.of("+11:00")).truncatedTo(ChronoUnit.SECONDS);
    ZonedDateTime date2 = date.plus(1, ChronoUnit.SECONDS);
    ZonedDateTime date3 = date.plus(2, ChronoUnit.SECONDS);
    String desc = "one";
    String desc2 = "two";
    String desc3 = "three\nthree";
    Path newFile = Files.createTempFile(workDir, "foo", ".txt");
    String fileName = newFile.toString();
    repository.hg(workDir, "add", fileName);
    repository.hg(workDir, "commit", "-u", user, "-d", date.toString(), "-m", desc);
    repository.hg(workDir, "branch", "other");
    Files.write(workDir.resolve(fileName), "hello".getBytes(UTF_8));
    repository.hg(workDir, "commit", "-u", user, "-d", date2.toString(), "-m", desc2);
    Path remoteDir = Files.createTempDirectory("remotedir");
    HgRepository remoteRepo = new HgRepository(remoteDir, /*verbose*/
    false, CommandRunner.DEFAULT_TIMEOUT);
    remoteRepo.init();
    Path newFile2 = Files.createTempFile(remoteDir, "bar", ".txt");
    String fileName2 = newFile2.toString();
    remoteRepo.hg(remoteDir, "add", fileName2);
    remoteRepo.hg(remoteDir, "commit", "-u", user, "-d", date3.toString(), "-m", desc3);
    repository.pullAll(remoteDir.toString());
    ImmutableList<HgLogEntry> allCommits = repository.log().run();
    assertThat(allCommits.size()).isEqualTo(3);
    assertThat(allCommits.get(0).getParents()).hasSize(1);
    assertThat(allCommits.get(0).getParents().get(0)).isEqualTo("0000000000000000000000000000000000000000");
    assertThat(allCommits.get(1).getParents().get(0)).isEqualTo(allCommits.get(2).getGlobalId());
    assertThat(allCommits.get(2).getParents().get(0)).isEqualTo("0000000000000000000000000000000000000000");
    assertThat(allCommits.get(0).getUser()).isEqualTo("Copy Bara <copy@bara.com>");
    assertThat(allCommits.get(0).getUser()).isEqualTo(allCommits.get(1).getUser());
    assertThat(allCommits.get(0).getUser()).isEqualTo(allCommits.get(2).getUser());
    assertThat(allCommits.get(0).getZonedDate()).isEqualTo(date3);
    assertThat(allCommits.get(1).getZonedDate()).isEqualTo(date2);
    assertThat(allCommits.get(2).getZonedDate()).isEqualTo(date);
    assertThat(allCommits.get(0).getBranch()).isEqualTo("default");
    assertThat(allCommits.get(1).getBranch()).isEqualTo("other");
    assertThat(allCommits.get(2).getBranch()).isEqualTo("default");
    assertThat(allCommits.get(0).getFiles()).containsExactly(newFile2.getFileName().toString());
    assertThat(allCommits.get(1).getFiles()).containsExactly(newFile.getFileName().toString());
    assertThat(allCommits.get(2).getFiles()).containsExactly(newFile.getFileName().toString());
    assertThat(allCommits.get(0).getDescription()).isEqualTo(desc3);
    assertThat(allCommits.get(1).getDescription()).isEqualTo(desc2);
    assertThat(allCommits.get(2).getDescription()).isEqualTo(desc);
    ImmutableList<HgLogEntry> defaultCommits = repository.log().withLimit(5).withBranch("default").run();
    assertThat(defaultCommits).hasSize(2);
    ImmutableList<HgLogEntry> otherCommits = repository.log().withLimit(5).withBranch("other").run();
    assertThat(otherCommits).hasSize(1);
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) ZonedDateTime(java.time.ZonedDateTime) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 5 with HgLogEntry

use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.

the class HgRepositoryTest method testLogLimit.

@Test
public void testLogLimit() throws Exception {
    Path newFile = addAndCommitFile("foo");
    Files.write(workDir.resolve(newFile.toString()), "hello".getBytes(UTF_8));
    repository.hg(workDir, "add", newFile.toString());
    repository.hg(workDir, "commit", "-m", "hello");
    ImmutableList<HgLogEntry> commits = repository.log().withLimit(1).run();
    assertThat(commits).hasSize(1);
    assertThrows(IllegalArgumentException.class, () -> repository.log().withLimit(0).run());
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Aggregations

HgLogEntry (com.google.copybara.hg.HgRepository.HgLogEntry)13 Test (org.junit.Test)12 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)9 Path (java.nio.file.Path)9 TransformResult (com.google.copybara.TransformResult)2 Author (com.google.copybara.authoring.Author)2 DummyRevision (com.google.copybara.testing.DummyRevision)2 ZonedDateTime (java.time.ZonedDateTime)2 ImmutableList (com.google.common.collect.ImmutableList)1 Change (com.google.copybara.Change)1 DestinationEffect (com.google.copybara.DestinationEffect)1 InvalidAuthorException (com.google.copybara.authoring.InvalidAuthorException)1 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)1 RepoException (com.google.copybara.exception.RepoException)1