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