Search in sources :

Example 6 with HgLogEntry

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");
}
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 7 with HgLogEntry

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);
}
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 8 with HgLogEntry

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();
}
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 9 with HgLogEntry

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");
}
Also used : TransformResult(com.google.copybara.TransformResult) DummyRevision(com.google.copybara.testing.DummyRevision) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Example 10 with HgLogEntry

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