Search in sources :

Example 6 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class WorkflowTest method testNonReversibleInsideGit.

@Test
public void testNonReversibleInsideGit() throws IOException, ValidationException, RepoException {
    origin.singleFileChange(0, "one commit", "foo.txt", "foo\nbar\n");
    GitRepository.newRepo(/*verbose*/
    true, workdir, getGitEnv()).init();
    Path subdir = Files.createDirectory(workdir.resolve("subdir"));
    String config = "" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = testing.origin(),\n" + "    destination = testing.destination(),\n" + "    transformations = [core.replace('foo', 'bar')],\n" + "    authoring = " + authoring + ",\n" + "    reversible_check = True,\n" + ")\n";
    Migration workflow = loadConfig(config).getMigration("default");
    ValidationException e = assertThrows(ValidationException.class, () -> workflow.run(subdir, ImmutableList.of()));
    assertThat(e).hasMessageThat().contains("Cannot use 'reversible_check = True' because Copybara temporary directory");
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) ValidationException(com.google.copybara.exception.ValidationException) Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 7 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class WorkflowTest method testFirstParentAlreadyImportedInNoFirstParent.

/**
 * Regression that test that when using git.origin with first_parent = False, if the first parent
 * of a merge is already imported and the merge is a no-op, we detect the import as
 * EmptyChangeException instead of detecting the non-first parent as the change to import
 */
@Test
public void testFirstParentAlreadyImportedInNoFirstParent() throws Exception {
    Path originPath = Files.createTempDirectory("origin");
    GitRepository origin = GitRepository.newRepo(/*verbose*/
    true, originPath, getGitEnv()).init();
    String primaryBranch = origin.getPrimaryBranch();
    options.setForce(false);
    options.workflowOptions.initHistory = true;
    String config = "core.workflow(" + "    name = 'default'," + "    origin = git.origin( url = 'file://" + origin.getWorkTree() + "',\n" + "                         ref = '" + primaryBranch + "',\n" + "                         first_parent = False),\n" + "    destination = testing.destination(),\n" + "    authoring = " + authoring + "," + "    origin_files = glob(['included/**'])," + "    mode = '" + WorkflowMode.SQUASH + "'," + ")\n";
    Migration workflow = loadConfig(config).getMigration("default");
    addGitFile(originPath, origin, "included/foo.txt", "");
    GitRevision lastRev = commit(origin, "last_rev");
    workflow.run(workdir, ImmutableList.of());
    assertThat(destination.processed.get(0).getOriginRef()).isEqualTo(lastRev);
    origin.simpleCommand("checkout", "-b", "feature");
    addGitFile(originPath, origin, "included/foo.txt", "SHOULD NOT BE IN PRIMARY");
    commit(origin, "feature commit");
    origin.simpleCommand("revert", "HEAD");
    addGitFile(originPath, origin, "excluded/bar.txt", "don't migrate!");
    commit(origin, "excluded commit");
    origin.simpleCommand("checkout", primaryBranch);
    origin.simpleCommand("merge", "-s", "ours", "feature");
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> workflow.run(workdir, ImmutableList.of()));
    assertThat(e).hasMessageThat().matches("No changes from " + lastRev.getSha1() + " up to .* match any origin_files.*");
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) GitRepository(com.google.copybara.git.GitRepository) GitRevision(com.google.copybara.git.GitRevision) Migration(com.google.copybara.config.Migration) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 8 with Migration

use of com.google.copybara.config.Migration 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)

Example 9 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testDefaultMirrorInStarlark.

/**
 * Starlark version of our native git.mirror implementation
 */
@Test
public void testDefaultMirrorInStarlark() throws Exception {
    String cfg = "" + NATIVE_MIRROR_IN_STARLARK_FUNC + "git.mirror(" + "    name = 'default'," + "    origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + "    destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + "    refspecs = [" + String.format("       'refs/heads/%s:refs/heads/origin_primary'", primaryBranch) + "    ]," + "    actions = [native_mirror(refspec = {" + String.format("       'refs/heads/%s':'refs/heads/origin_primary'", primaryBranch) + "})]," + ")";
    Migration mirror = loadMigration(cfg, "default");
    mirror.run(workdir, ImmutableList.of());
    String origPrimary = originRepo.git(originRepo.getGitDir(), "show-ref", primaryBranch, "-s").getStdout();
    String dest = destRepo.git(destRepo.getGitDir(), "show-ref", "origin_primary", "-s").getStdout();
    assertThat(dest).isEqualTo(origPrimary);
    checkRefDoesntExist("refs/heads/" + primaryBranch);
    checkRefDoesntExist("refs/heads/other");
}
Also used : Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 10 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testMerge.

@Test
public void testMerge() throws Exception {
    Migration mirror = mergeInit();
    GitLogEntry destChange = repoChange(destRepo, "some_file", "Content", "destination only");
    GitLogEntry originChange = repoChange(originRepo, "some_other_file", "Content", "new change");
    mirror.run(workdir, ImmutableList.of());
    GitLogEntry merge = lastChange(destRepo, primaryBranch);
    // It is a merge
    assertThat(merge.getParents()).containsExactly(destChange.getCommit(), originChange.getCommit());
    // OSS branch is updated with origin version.
    assertThat(lastChange(destRepo, "oss").getCommit()).isEqualTo(originChange.getCommit());
}
Also used : Migration(com.google.copybara.config.Migration) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Aggregations

Migration (com.google.copybara.config.Migration)30 Test (org.junit.Test)22 ValidationException (com.google.copybara.exception.ValidationException)9 Path (java.nio.file.Path)9 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)7 GitRepository (com.google.copybara.git.GitRepository)6 Config (com.google.copybara.config.Config)5 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)3 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)3 TestingEventMonitor (com.google.copybara.testing.TestingEventMonitor)3 Console (com.google.copybara.util.console.Console)3 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)3 Before (org.junit.Before)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 MigrationReference (com.google.copybara.Info.MigrationReference)2 Author (com.google.copybara.authoring.Author)2