Search in sources :

Example 11 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException 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 12 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class WorkflowTest method testSquashAlreadyMigrated.

@Test
public void testSquashAlreadyMigrated() throws Exception {
    origin.addSimpleChange(/*timestamp*/
    1);
    String oldRef = resolveHead();
    origin.addSimpleChange(/*timestamp*/
    2);
    origin.addSimpleChange(/*timestamp*/
    3);
    includeReleaseNotes = true;
    options.setForce(true);
    skylarkWorkflow("default", SQUASH).run(workdir, ImmutableList.of(HEAD));
    // Disable force so that we get an error
    options.setForce(false);
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> skylarkWorkflow("default", SQUASH).run(workdir, ImmutableList.of(oldRef)));
    assertThat(thrown).hasMessageThat().contains("'0' has been already migrated");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 13 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class WorkflowTest method testFailWithNoopFunc.

@Test
public void testFailWithNoopFunc() throws Exception {
    Transformation transformation = ((Workflow<?, ?>) loadConfig("" + "def fail_test(ctx):\n" + "  core.fail_with_noop('Hello, this is empty!')\n" + "" + "core.workflow(\n" + "    name = 'default',\n" + "    authoring = " + authoring + "\n," + "    origin = testing.origin(),\n" + "    destination = testing.destination(),\n" + "    transformations = [fail_test]," + ")\n").getMigration("default")).getTransformation();
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> transformation.transform(TransformWorks.of(workdir, "message", console())));
    assertThat(e).hasMessageThat().contains("Hello, this is empty!");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 14 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class WorkflowTest method testSquashEmptyChangeWithForceFalse.

@Test
public void testSquashEmptyChangeWithForceFalse() throws Exception {
    originFiles = "glob(['foo/**'], exclude = ['copy.bara.sky', 'excluded/**'])";
    transformations = ImmutableList.of();
    options.workflowOptions.initHistory = true;
    origin.singleFileChange(0, "change 1", "bar/file.txt", "a");
    options.setForce(false);
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> skylarkWorkflow("default", SQUASH).run(workdir, ImmutableList.of("0")));
    assertThat(e).hasMessageThat().contains("No changes up to 0 match any origin_files. " + "Use --force if you really want to run the migration anyway.");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 15 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GerritOriginTest method testBranchFiltering.

@Test
public void testBranchFiltering() throws Exception {
    mockChange(12345);
    GerritOrigin origin = skylark.eval("g", "g = git.gerrit_origin(" + "  url = 'https://" + REPO_URL + "'," + "  branch = 'master')");
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> origin.resolve("12345"));
    assertThat(e).hasMessageThat().contains("Skipping import of change 12345 for branch my_branch");
    // But this should work, as the last-rev needs to be resolved:
    origin.resolve(firstRevision.getSha1());
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Aggregations

EmptyChangeException (com.google.copybara.exception.EmptyChangeException)42 Test (org.junit.Test)27 ImmutableList (com.google.common.collect.ImmutableList)10 RepoException (com.google.copybara.exception.RepoException)10 ValidationException (com.google.copybara.exception.ValidationException)10 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)10 Path (java.nio.file.Path)10 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)8 Endpoint (com.google.copybara.Endpoint)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 CharMatcher (com.google.common.base.CharMatcher)5 Preconditions (com.google.common.base.Preconditions)5 Splitter (com.google.common.base.Splitter)5 Collections2 (com.google.common.collect.Collections2)5 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)5 Iterables (com.google.common.collect.Iterables)5 Sets (com.google.common.collect.Sets)5 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)5 BaselinesWithoutLabelVisitor (com.google.copybara.BaselinesWithoutLabelVisitor)5 Change (com.google.copybara.Change)5