use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.
the class HgRepositoryTest method testLogRefExpression.
@Test
public void testLogRefExpression() throws Exception {
Path newFile = addAndCommitFile("foo");
Files.write(workDir.resolve(newFile.toString()), "hello".getBytes(UTF_8));
repository.hg(workDir, "commit", "-m", "say hello");
repository.hg(workDir, "rm", newFile.toString());
repository.hg(workDir, "commit", "-m", "remove foo");
ImmutableList<HgLogEntry> commits = repository.log().run();
ImmutableList<HgLogEntry> testCommits = repository.log().withReferenceExpression("1:2").run();
assertThat(testCommits).hasSize(2);
assertThat(testCommits.get(0).getGlobalId()).isEqualTo(commits.get(1).getGlobalId());
assertThat(testCommits.get(1).getGlobalId()).isEqualTo(commits.get(0).getGlobalId());
verifyThrowsValidationException("not_a_ref_expression", "Unknown revision");
verifyThrowsRepoException("??", "Syntax error");
verifyThrowsRepoException(" ", "Cannot log null or empty reference");
verifyThrowsRepoException("invalid reference", "parse error");
}
use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.
the class HgRepositoryTest method testLogMultipleFiles.
@Test
public void testLogMultipleFiles() throws Exception {
Path newFile = Files.createTempFile(workDir, "foo", ".txt");
Path newFile2 = Files.createTempFile(workDir, "bar", ".txt");
String fileName = newFile.toString();
String fileName2 = newFile2.toString();
repository.hg(workDir, "add", fileName);
repository.hg(workDir, "add", fileName2);
repository.hg(workDir, "commit", "-m", "add 2 files");
ImmutableList<HgLogEntry> commits = repository.log().run();
assertThat(commits.get(0).getFiles()).hasSize(2);
}
use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.
the class HgOriginTest method testCheckout.
@Test
public void testCheckout() throws Exception {
Reader<HgRevision> reader = newReader();
Path workDir = Files.createTempDirectory("workDir");
Files.write(remotePath.resolve("foo.txt"), "hello".getBytes(UTF_8));
Files.write(remotePath.resolve("bar.txt"), "hello".getBytes(UTF_8));
repository.hg(remotePath, "add", "foo.txt");
repository.hg(remotePath, "add", "bar.txt");
repository.hg(remotePath, "commit", "-m", "foo");
Files.write(remotePath.resolve("foo.txt"), "goodbye".getBytes(UTF_8));
Files.write(remotePath.resolve("bar.txt"), "other".getBytes(UTF_8));
repository.hg(remotePath, "add", "foo.txt");
repository.hg(remotePath, "commit", "-m", "bye");
repository.hg(remotePath, "rm", "foo.txt");
repository.hg(remotePath, "commit", "-m", "rm foo");
ImmutableList<HgLogEntry> commits = repository.log().run();
reader.checkout(origin.resolve(commits.get(2).getGlobalId()), workDir);
assertThatPath(workDir).containsFile("foo.txt", "hello").containsFile("bar.txt", "hello").containsFiles(".hg_archival.txt").containsNoMoreFiles();
reader.checkout(origin.resolve(commits.get(1).getGlobalId()), workDir);
assertThatPath(workDir).containsFile("foo.txt", "goodbye").containsFile("bar.txt", "other").containsFiles(".hg_archival.txt").containsNoMoreFiles();
reader.checkout(origin.resolve(commits.get(0).getGlobalId()), workDir);
assertThatPath(workDir).containsFile("bar.txt", "other").containsFiles(".hg_archival.txt").containsNoMoreFiles();
}
use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.
the class HgDestinationTest method testWriteDeletesAndAddsFiles.
@Test
public void testWriteDeletesAndAddsFiles() throws Exception {
Files.write(workdir.resolve("delete_me.txt"), "deleted content".getBytes(UTF_8));
DummyRevision deletedRef = new DummyRevision("delete_ref");
TransformResult result = TransformResults.of(workdir, deletedRef);
writer.write(result, destinationFiles, console);
workdir = options.general.getDirFactory().newTempDir("testWriteDeletesAndAddsFiles-workdir");
Files.write(workdir.resolve("add_me.txt"), "added content".getBytes(UTF_8));
createRevisionAndWrite("add_ref");
remoteRepo.cleanUpdate("tip");
ImmutableList<HgLogEntry> commits = remoteRepo.log().run();
assertThat(commits).hasSize(3);
assertThat(commits.get(0).getFiles()).hasSize(2);
assertThat(commits.get(0).getFiles().get(0)).isEqualTo("add_me.txt");
assertThat(commits.get(0).getFiles().get(1)).isEqualTo("delete_me.txt");
assertThat(commits.get(1).getFiles()).hasSize(2);
assertThat(commits.get(1).getFiles().get(0)).isEqualTo("delete_me.txt");
assertThat(commits.get(1).getFiles().get(1)).isEqualTo("file.txt");
assertThatPath(hgDestPath).containsFile("add_me.txt", "added content");
assertThatPath(hgDestPath).containsNoFiles("delete_me.txt");
assertThatPath(hgDestPath).containsNoFiles("file.txt");
}
use of com.google.copybara.hg.HgRepository.HgLogEntry in project copybara by google.
the class HgRepositoryTest method testPullFromRef.
@Test
public void testPullFromRef() throws Exception {
addAndCommitFile("foo");
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", "-m", "foo");
Path newFile3 = Files.createTempFile(remoteDir, "foobar", ".txt");
String fileName3 = newFile3.toString();
remoteRepo.hg(remoteDir, "add", fileName3);
remoteRepo.hg(remoteDir, "commit", "-m", "foobar");
Path newFile4 = Files.createTempFile(remoteDir, "barfoo", ".txt");
String fileName4 = newFile4.toString();
remoteRepo.hg(remoteDir, "add", fileName4);
remoteRepo.hg(remoteDir, "commit", "-m", "barfoo");
ImmutableList<HgLogEntry> remoteCommits = remoteRepo.log().run();
repository.pullFromRef(remoteDir.toString(), remoteCommits.get(1).getGlobalId());
ImmutableList<HgLogEntry> commits = repository.log().run();
assertThat(commits).hasSize(3);
assertThat(commits.get(0).getGlobalId()).isEqualTo(remoteCommits.get(1).getGlobalId());
}
Aggregations