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