Search in sources :

Example 11 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testMirrorNoConflictIfForce.

@Test
public void testMirrorNoConflictIfForce() throws Exception {
    options.setForce(true);
    Migration mirror = prepareForConflict();
    mirror.run(workdir, ImmutableList.of());
}
Also used : Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 12 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testDefaultMirrorInStarlark_invalid_destination.

@Test
public void testDefaultMirrorInStarlark_invalid_destination() 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 = {" + String.format("       'refs/heads/%s':'refs/heads/INVALID'", primaryBranch) + "})]," + ")";
    Migration mirror = loadMigration(cfg, "default");
    ValidationException ve = assertThrows(ValidationException.class, () -> mirror.run(workdir, ImmutableList.of()));
    assertThat(ve).hasMessageThat().contains("Action tried to push to destination 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 13 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testMergeConflict.

@Test
public void testMergeConflict() throws Exception {
    Migration mirror = mergeInit();
    GitLogEntry destChange = repoChange(destRepo, "some_file", "Hello", "destination only");
    GitLogEntry originChange = repoChange(originRepo, "some_file", "Bye", "new change");
    assertThat((assertThrows(ValidationException.class, new ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            mirror.run(workdir, ImmutableList.of());
        }
    }))).hasMessageThat().contains("Conflict merging refs/heads/" + primaryBranch);
}
Also used : Migration(com.google.copybara.config.Migration) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 14 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testMirrorDryRun.

@Test
public void testMirrorDryRun() throws Exception {
    Migration mirror = createMirrorObj();
    mirror.run(workdir, ImmutableList.of());
    String orig = originRepo.git(originRepo.getGitDir(), "show-ref").getStdout();
    String dest = destRepo.git(destRepo.getGitDir(), "show-ref").getStdout();
    assertThat(dest).isEqualTo(orig);
    options.general.dryRunMode = true;
    mirror = createMirrorObj();
    String destOld = destRepo.git(destRepo.getGitDir(), "show-ref").getStdout();
    Files.write(originRepo.getWorkTree().resolve("test.txt"), "updated content".getBytes(UTF_8));
    originRepo.add().files("test.txt").run();
    originRepo.simpleCommand("commit", "-m", "first file");
    mirror.run(workdir, ImmutableList.of());
    orig = originRepo.git(originRepo.getGitDir(), "show-ref").getStdout();
    dest = destRepo.git(destRepo.getGitDir(), "show-ref").getStdout();
    assertThat(dest).isNotEqualTo(orig);
    assertThat(dest).isEqualTo(destOld);
}
Also used : Migration(com.google.copybara.config.Migration) Test(org.junit.Test)

Example 15 with Migration

use of com.google.copybara.config.Migration in project copybara by google.

the class GitMirrorTest method testMirrorPrune.

@Test
public void testMirrorPrune() throws Exception {
    GitRepository destRepo1 = bareRepo(Files.createTempDirectory("dest1"));
    destRepo1.init();
    String cfg = "" + "git.mirror(" + "    name = 'default'," + "    origin = 'file://" + originRepo.getGitDir().toAbsolutePath() + "'," + "    destination = 'file://" + destRepo.getGitDir().toAbsolutePath() + "'," + "    prune = True," + ")\n" + "";
    Migration migration = loadMigration(cfg, "default");
    migration.run(workdir, ImmutableList.of());
    originRepo.simpleCommand("branch", "-D", "other");
    migration.run(workdir, ImmutableList.of());
    checkRefDoesntExist("refs/heads/other");
}
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