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