Search in sources :

Example 11 with HgLogEntry

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

the class HgRepositoryTest method testIdentify.

@Test
public void testIdentify() throws Exception {
    addAndCommitFile("foo");
    ImmutableList<HgLogEntry> commits = repository.log().run();
    String globalId = commits.get(0).getGlobalId();
    for (String reference : ImmutableList.of(globalId, "tip", String.valueOf(0), "default")) {
        HgRevision revision = repository.identify(reference);
        assertThat(revision.getGlobalId()).isEqualTo(globalId);
        assertThat(revision.contextReference()).isEqualTo(reference);
    }
    CannotResolveRevisionException expected = assertThrows(CannotResolveRevisionException.class, () -> repository.identify("not_a_branch"));
    assertThat(expected.getMessage()).contains("Unknown revision");
}
Also used : CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 12 with HgLogEntry

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

the class HgRepositoryTest method testCleanUpdate.

@Test
public void testCleanUpdate() throws Exception {
    Path newFile = addAndCommitFile("foo");
    Path newFile2 = addAndCommitFile("bar");
    Path newFile3 = Files.createTempFile(workDir, "foobar", ".txt");
    String fileName3 = newFile3.toString();
    repository.hg(workDir, "add", fileName3);
    ImmutableList<HgLogEntry> commits = repository.log().run();
    repository.cleanUpdate(commits.get(1).getGlobalId());
    assertThat(commits).hasSize(2);
    assertThat(Files.exists(newFile)).isTrue();
    assertThat(Files.notExists(newFile2)).isTrue();
    /*
    Hg does not delete untracked files on update. In practice, this is ok because there should
    be no untracked files as the workDir is deleted every time.
     */
    assertThat(Files.exists(newFile3)).isTrue();
}
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 13 with HgLogEntry

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

the class HgRepositoryTest method testLogNoFiles.

@Test
public void testLogNoFiles() throws Exception {
    Path newFile = addAndCommitFile("foo");
    repository.hg(workDir, "rm", newFile.toString());
    repository.hg(workDir, "commit", "--amend", "-m", "amend");
    ImmutableList<HgLogEntry> commits = repository.log().run();
    assertThat(commits.get(0).getFiles()).hasSize(0);
}
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