Search in sources :

Example 31 with EmptyChangeException

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

the class WorkflowTest method changeRequestEmptyChanges.

@Test
public void changeRequestEmptyChanges() throws Exception {
    Path originPath = Files.createTempDirectory("origin");
    GitRepository origin = GitRepository.newRepo(/*verbose*/
    true, originPath, getGitEnv()).init();
    String primaryBranch = origin.getPrimaryBranch();
    String config = "def after_all(ctx):\n" + "  ctx.destination.message('after_all '" + " + str([e.type + ' '+ e.summary for e in ctx.effects]))\n" + "\n" + "core.workflow(" + "    name = 'default'," + String.format("    origin = git.origin( url = 'file://%s', ref = '%s'),\n", origin.getWorkTree(), primaryBranch) + "    destination = testing.destination(),\n" + "    authoring = " + authoring + "," + "    origin_files = glob(['included/**'])," + "    mode = '" + WorkflowMode.CHANGE_REQUEST + "'," + "    after_workflow = [after_all]" + ")\n";
    Migration workflow = loadConfig(config).getMigration("default");
    Files.createDirectory(originPath.resolve("included"));
    Files.write(originPath.resolve("included/foo.txt"), "a".getBytes(UTF_8));
    origin.add().files("included/foo.txt").run();
    origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "the baseline\n\n" + destination.getLabelNameWhenOrigin() + "=42");
    Files.createDirectory(originPath.resolve("excluded"));
    Files.write(originPath.resolve("excluded/foo.txt"), "a".getBytes(UTF_8));
    origin.add().files("excluded/foo.txt").run();
    origin.commit("Foo <foo@bara.com>", ZonedDateTime.now(ZoneId.systemDefault()), "head change");
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> workflow.run(workdir, ImmutableList.of()));
    assertThat(thrown).hasMessageThat().contains("doesn't include any change for origin_files = glob(include = [\"included/**\"])");
    assertThat(destination.getEndpoint().messages).hasSize(1);
    assertThat(destination.getEndpoint().messages.get(0)).containsMatch(".*didn't affect any destination file.*");
}
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) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 32 with EmptyChangeException

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

the class WorkflowTest method iterativeWorkflowEmptyChanges.

@Test
public void iterativeWorkflowEmptyChanges() throws Exception {
    origin.addSimpleChange(/*timestamp*/
    1);
    Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
    "0");
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> workflow.run(workdir, ImmutableList.of("0")));
    assertThat(thrown).hasMessageThat().contains("No new changes to import for resolved ref: 0");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 33 with EmptyChangeException

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

the class WorkflowTest method checkIterativeModeWithError.

@SuppressWarnings("unchecked")
private <T extends Exception> T checkIterativeModeWithError(T exception) throws IOException, ValidationException {
    for (int timestamp = 0; timestamp < 10; timestamp++) {
        origin.addSimpleChange(timestamp);
    }
    // Override destination with one that always throws EmptyChangeException.
    options.testingOptions.destination = new RecordsProcessCallDestination() {

        @Override
        public Writer<Revision> newWriter(WriterContext writerContext) {
            return new WriterImpl(writerContext.isDryRun()) {

                @Override
                public ImmutableList<DestinationEffect> write(TransformResult transformResult, Glob destinationFiles, Console console) throws ValidationException, RepoException {
                    assert exception != null;
                    Throwables.propagateIfPossible(exception, ValidationException.class, RepoException.class);
                    throw new RuntimeException(exception);
                }
            };
        }
    };
    Workflow<?, ?> workflow = iterativeWorkflow(/*previousRef=*/
    "1");
    try {
        workflow.run(workdir, ImmutableList.of("3"));
        fail();
    } catch (Exception expected) {
        assertThat(expected).isInstanceOf(expected.getClass());
        return (T) expected;
    }
    return exception;
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ValidationException(com.google.copybara.exception.ValidationException) ImmutableList(com.google.common.collect.ImmutableList) RepoException(com.google.copybara.exception.RepoException) ChangeRejectedException(com.google.copybara.exception.ChangeRejectedException) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) VoidOperationException(com.google.copybara.exception.VoidOperationException) NotADestinationFileException(com.google.copybara.exception.NotADestinationFileException) RepoException(com.google.copybara.exception.RepoException) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Console(com.google.copybara.util.console.Console) Glob(com.google.copybara.util.Glob)

Example 34 with EmptyChangeException

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

the class GitDestinationTest method processEmptyCommit.

@Test
public void processEmptyCommit() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    DummyRevision ref = new DummyRevision("origin_ref");
    process(firstCommitWriter(), ref);
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> process(newWriter(), ref));
    assertThat(thrown).hasMessageThat().contains("empty change");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 35 with EmptyChangeException

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

the class GitDestinationTest method processEmptyCommitWithExcludes.

@Test
public void processEmptyCommitWithExcludes() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("excluded"), "some content".getBytes(UTF_8));
    repo().withWorkTree(workdir).add().files("excluded").run();
    repo().withWorkTree(workdir).simpleCommand("commit", "-m", "first commit");
    Files.delete(workdir.resolve("excluded"));
    destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("excluded"));
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> process(newWriter(), new DummyRevision("origin_ref")));
    assertThat(thrown).hasMessageThat().contains("empty change");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) 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