Search in sources :

Example 26 with Migration

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");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 27 with Migration

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");
}
Also used : Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 28 with Migration

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.*");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 29 with Migration

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()));
}
Also used : Migration(com.google.copybara.config.Migration)

Example 30 with Migration

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());
}
Also used : Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Aggregations

Migration (com.google.copybara.config.Migration)30 Test (org.junit.Test)22 ValidationException (com.google.copybara.exception.ValidationException)9 Path (java.nio.file.Path)9 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)7 GitRepository (com.google.copybara.git.GitRepository)6 Config (com.google.copybara.config.Config)5 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)3 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)3 TestingEventMonitor (com.google.copybara.testing.TestingEventMonitor)3 Console (com.google.copybara.util.console.Console)3 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)3 Before (org.junit.Before)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 MigrationReference (com.google.copybara.Info.MigrationReference)2 Author (com.google.copybara.authoring.Author)2