use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testDefaultMirrorInStarlark_invalid_origin.
@Test
public void testDefaultMirrorInStarlark_invalid_origin() 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 = {" + " 'refs/heads/INVALID':'refs/heads/origin_primary'" + "})]," + ")";
Migration mirror = loadMigration(cfg, "default");
ValidationException ve = assertThrows(ValidationException.class, () -> mirror.run(workdir, ImmutableList.of()));
assertThat(ve).hasMessageThat().contains("Action tried to fetch from origin one or more refspec not covered by git.mirror");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testMirrorCustomRefspec.
@Test
public void testMirrorCustomRefspec() throws Exception {
String cfg = "" + "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) + " ]" + ")";
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");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testMirrorConflict.
@Test
public void testMirrorConflict() throws Exception {
Migration mirror = prepareForConflict();
ValidationException e = assertThrows(ValidationException.class, () -> mirror.run(workdir, ImmutableList.of()));
assertThat(e).hasMessageThat().matches(".*Failed to push to .*" + "because local/origin history is behind destination.*");
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method checkActionFailure.
private ValidationException checkActionFailure() throws IOException, ValidationException {
String cfg = "" + "def a1(ctx):\n" + " ctx.console.info(\'Hello, this is action1\')\n" + " return ctx.error('Something bad happened')\n" + "\n" + "def a2(ctx):\n" + " ctx.console.info(\'Hello, this is action2\')\n" + " return ctx.error('Another thing bad happened')\n" + "\n" + "def a3(ctx):\n" + " ctx.console.info(\'Hello, this is action3\')\n" + " return ctx.success()\n" + "\n" + "git.mirror(" + " name = 'default'," + " origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + " destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + " actions = [a1, a2, a3]" + ")\n" + "";
Migration migration = loadMigration(cfg, "default");
return assertThrows(ValidationException.class, () -> migration.run(workdir, ImmutableList.of()));
}
use of com.google.copybara.config.Migration in project copybara by google.
the class GitMirrorTest method testMirrorNoConflictIfGitMirrorForce.
@Test
public void testMirrorNoConflictIfGitMirrorForce() throws Exception {
options.gitMirrorOptions.forcePush = true;
Migration mirror = prepareForConflict();
mirror.run(workdir, ImmutableList.of());
}
Aggregations