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.*");
}
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");
}
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;
}
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");
}
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");
}
Aggregations