Search in sources :

Example 1 with HgRepository

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

the class WorkflowTest method testHgOriginNoFlags.

@Test
public void testHgOriginNoFlags() throws Exception {
    Path originPath = Files.createTempDirectory("origin");
    HgRepository origin = new HgRepository(originPath, true, DEFAULT_TIMEOUT).init();
    Path destinationPath = Files.createTempDirectory("destination");
    GitRepository destRepo = GitRepository.newBareRepo(destinationPath, getGitEnv(), true, DEFAULT_TIMEOUT, /*noVerify=*/
    false).init();
    String primaryBranch = destRepo.getPrimaryBranch();
    String config = "core.workflow(" + "    name = 'default'," + "    origin = hg.origin( url = 'file://" + origin.getHgDir() + "', ref = 'default'),\n" + "    destination = git.destination(" + "                                  url = 'file://" + destRepo.getGitDir() + "',\n" + "                                  fetch = '" + primaryBranch + "',\n" + "                                  push = '" + primaryBranch + "',\n" + "    ),\n" + "    authoring = " + authoring + "," + "    mode = '" + WorkflowMode.ITERATIVE + "'," + ")\n";
    Files.write(originPath.resolve("foo.txt"), "testing foo".getBytes(UTF_8));
    origin.hg(originPath, "add", "foo.txt");
    origin.hg(originPath, "commit", "-m", "add foo");
    options.gitDestination.committerName = "Foo";
    options.gitDestination.committerEmail = "foo@foo.com";
    options.setWorkdirToRealTempDir();
    options.setHomeDir(Files.createTempDirectory("home").toString());
    options.workflowOptions.initHistory = true;
    Migration workflow = loadConfig(config).getMigration("default");
    workflow.run(workdir, ImmutableList.of());
    ImmutableList<GitLogEntry> destCommits = destRepo.log("HEAD").run();
    assertThat(destCommits).hasSize(1);
    assertThat(destCommits.get(0).getBody()).contains("add foo");
    Files.write(originPath.resolve("bar.txt"), "testing bar".getBytes(UTF_8));
    origin.hg(originPath, "add", "bar.txt");
    origin.hg(originPath, "commit", "-m", "add bar");
    options.workflowOptions.initHistory = false;
    workflow.run(workdir, ImmutableList.of());
    destCommits = destRepo.log("HEAD").run();
    assertThat(destCommits).hasSize(2);
    assertThat(destCommits.get(0).getBody()).contains("add bar");
    assertThat(destCommits.get(1).getBody()).contains("add foo");
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) GitRepository(com.google.copybara.git.GitRepository) Migration(com.google.copybara.config.Migration) HgRepository(com.google.copybara.hg.HgRepository) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Aggregations

Migration (com.google.copybara.config.Migration)1 GitRepository (com.google.copybara.git.GitRepository)1 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)1 HgRepository (com.google.copybara.hg.HgRepository)1 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1