use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method test_force_rewrite_history.
@Test
public void test_force_rewrite_history() throws Exception {
fetch = primaryBranch;
push = "feature";
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("excluded.txt"));
Path scratchTree = Files.createTempDirectory("GitDestinationTest-scratchTree");
Files.write(scratchTree.resolve("excluded.txt"), "some content".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().files("excluded.txt").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-m", "primary change");
Path file = workdir.resolve("test.txt");
Files.write(file, "some content".getBytes(UTF_8));
Writer<GitRevision> writer = newWriter();
assertThat(writer.getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME)).isNull();
process(writer, new DummyRevision("first_commit"));
assertCommitHasOrigin("feature", "first_commit");
Files.write(file, "changed".getBytes(UTF_8));
process(writer, new DummyRevision("second_commit"));
assertCommitHasOrigin("feature", "second_commit");
options.gitDestination.nonFastForwardPush = true;
Files.write(file, "some content".getBytes(UTF_8));
writer = newWriter();
assertThat(writer.getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME)).isNull();
process(writer, new DummyRevision("first_commit_2"));
assertCommitHasOrigin("feature", "first_commit_2");
Files.write(file, "changed".getBytes(UTF_8));
process(writer, new DummyRevision("second_commit_2"));
assertCommitHasOrigin("feature", "second_commit_2");
assertThat(repo().log(primaryBranch + "..feature").run()).hasSize(2);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method processEmptyDiff.
@Test
public void processEmptyDiff() throws Exception {
console = new TestingConsole().respondYes();
fetch = primaryBranch;
push = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
processWithBaselineAndConfirmation(firstCommitWriter(), destinationFiles, new DummyRevision("origin_ref1"), /*baseline=*/
null, /*askForConfirmation=*/
true);
// process empty change. Shouldn't ask anything.
assertThrows(EmptyChangeException.class, () -> processWithBaselineAndConfirmation(newWriter(), destinationFiles, new DummyRevision("origin_ref2"), /*baseline=*/
null, /*askForConfirmation=*/
true));
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method previousRebaseFailureDoesNotAffectNextOne.
@Test
public void previousRebaseFailureDoesNotAffectNextOne() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
GitRepository destRepo = repo().withWorkTree(workdir);
writeFile(workdir, "foo", "");
destRepo.add().files("foo").run();
destRepo.simpleCommand("commit", "-m", "baseline");
GitRevision baseline = destRepo.resolveReference("HEAD");
writeFile(workdir, "foo", "conflict");
destRepo.add().files("foo").run();
destRepo.simpleCommand("commit", "-m", "primary head");
writeFile(workdir, "foo", "updated");
destinationFiles = Glob.createGlob(ImmutableList.of("foo"));
RebaseConflictException rebaseConflictException = assertThrows(RebaseConflictException.class, () -> processWithBaseline(newWriter(), destinationFiles, new DummyRevision("origin_ref"), baseline.getSha1()));
writeFile(workdir, "foo", "conflict");
writeFile(workdir, "bar", "other file");
destinationFiles = Glob.createGlob(ImmutableList.of("foo", "bar"));
processWithBaseline(newWriter(), destinationFiles, new DummyRevision("origin_ref"), baseline.getSha1());
assertThat(rebaseConflictException).hasMessageThat().containsMatch(".*Please consider to use flag nogit-destination-rebase to workaround.*");
assertThatCheckout(destRepo, "HEAD").containsFile("foo", "conflict").containsFile("bar", "other file").containsNoMoreFiles();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method lastRevOnlyForAffectedRoots.
@Test
public void lastRevOnlyForAffectedRoots() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.createDirectories(workdir.resolve("foo"));
Files.createDirectories(workdir.resolve("bar"));
Files.createDirectories(workdir.resolve("baz"));
Files.write(workdir.resolve("foo/one"), "content".getBytes(UTF_8));
Files.write(workdir.resolve("bar/one"), "content".getBytes(UTF_8));
Files.write(workdir.resolve("baz/one"), "content".getBytes(UTF_8));
DummyRevision ref1 = new DummyRevision("first");
Glob firstGlob = Glob.createGlob(ImmutableList.of("foo/**", "bar/**"));
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destinationFirstCommit().newWriter(writerContext);
process(writer, ref1);
Files.write(workdir.resolve("baz/one"), "content2".getBytes(UTF_8));
DummyRevision ref2 = new DummyRevision("second");
process(writer, Glob.createGlob(ImmutableList.of("baz/**")), ref2);
assertThat(destination().newWriter(writerContext).getDestinationStatus(firstGlob, DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo(ref1.asString());
assertThat(writer.getDestinationStatus(Glob.createGlob(ImmutableList.of("baz/**")), DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo(ref2.asString());
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method gitUserEmailMustBeConfigured.
@Test
public void gitUserEmailMustBeConfigured() throws Exception {
options.gitDestination.committerName = "Foo Bara";
options.gitDestination.committerEmail = "";
fetch = primaryBranch;
push = primaryBranch;
ValidationException thrown = assertThrows(ValidationException.class, () -> process(firstCommitWriter(), new DummyRevision("first_commit")));
assertThat(thrown).hasMessageThat().contains("'user.name' and/or 'user.email' are not configured.");
}
Aggregations