Search in sources :

Example 41 with DummyRevision

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);
}
Also used : Path(java.nio.file.Path) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 42 with DummyRevision

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));
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 43 with DummyRevision

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

Example 44 with DummyRevision

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());
}
Also used : WriterContext(com.google.copybara.WriterContext) DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) Test(org.junit.Test)

Example 45 with DummyRevision

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

Aggregations

DummyRevision (com.google.copybara.testing.DummyRevision)144 Test (org.junit.Test)124 WriterContext (com.google.copybara.WriterContext)58 Path (java.nio.file.Path)29 DestinationEffect (com.google.copybara.DestinationEffect)28 Author (com.google.copybara.authoring.Author)21 Changes (com.google.copybara.Changes)19 Glob (com.google.copybara.util.Glob)19 ValidationException (com.google.copybara.exception.ValidationException)18 IOException (java.io.IOException)16 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)14 TransformResult (com.google.copybara.TransformResult)13 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)13 ZonedDateTime (java.time.ZonedDateTime)13 TransformWork (com.google.copybara.TransformWork)12 RepoException (com.google.copybara.exception.RepoException)12 CheckerException (com.google.copybara.checks.CheckerException)11 DummyChecker (com.google.copybara.testing.DummyChecker)11 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)11 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)11