Search in sources :

Example 31 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method testVisit.

@Test
public void testVisit() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    DummyRevision ref1 = new DummyRevision("origin_ref1");
    DummyRevision ref2 = new DummyRevision("origin_ref2");
    Files.write(workdir.resolve("test.txt"), "Visit me".getBytes(UTF_8));
    process(firstCommitWriter(), ref1);
    Files.write(workdir.resolve("test.txt"), "Visit me soon".getBytes(UTF_8));
    process(newWriter(), ref2);
    List<Change<?>> visited = new ArrayList<>();
    newWriter().visitChanges(null, input -> {
        visited.add(input);
        return input.getLabels().get(DummyOrigin.LABEL_NAME).contains("origin_ref1") ? VisitResult.TERMINATE : VisitResult.CONTINUE;
    });
    assertThat(visited).hasSize(2);
    assertThat(visited.get(0).getLabels().get(DummyOrigin.LABEL_NAME)).containsExactly("origin_ref2");
    assertThat(visited.get(1).getLabels().get(DummyOrigin.LABEL_NAME)).containsExactly("origin_ref1");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) ArrayList(java.util.ArrayList) Change(com.google.copybara.Change) Test(org.junit.Test)

Example 32 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method testGitIgnoreExcluded.

@Test
public void testGitIgnoreExcluded() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    Path scratchTree = Files.createTempDirectory("GitDestinationTest-testGitIgnoreExcluded");
    Files.write(scratchTree.resolve(".gitignore"), ".gitignore\n".getBytes(UTF_8));
    repo().withWorkTree(scratchTree).add().force().files(".gitignore").run();
    repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "gitignore file");
    destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of(".gitignore"));
    DummyRevision ref = new DummyRevision("origin_ref");
    process(newWriter(), ref);
    assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsFile(".gitignore", ".gitignore\n").containsNoMoreFiles();
}
Also used : Path(java.nio.file.Path) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 33 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method processWithBaselineSameFileConflict.

@Test
public void processWithBaselineSameFileConflict() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    DummyRevision ref = new DummyRevision("origin_ref");
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    process(firstCommitWriter(), ref);
    String firstCommit = repo().parseRef("HEAD");
    Files.write(workdir.resolve("test.txt"), "new content".getBytes(UTF_8));
    process(newWriter(), ref);
    Files.write(workdir.resolve("test.txt"), "conflict content".getBytes(UTF_8));
    RebaseConflictException thrown = assertThrows(RebaseConflictException.class, () -> processWithBaseline(newWriter(), destinationFiles, ref, firstCommit));
    assertThat(thrown).hasMessageThat().contains("conflict in test.txt");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 34 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method multipleMigrationsToOneDestination_separateRoots.

/**
 * Verify that multiple (exclusive) migrations can write to the same Git repository. This is,
 * migrations from different origins writing to a different subpaths in the Git repo and excluding
 * the other ones.
 */
@Test
public void multipleMigrationsToOneDestination_separateRoots() 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"), "First version".getBytes(UTF_8));
    Files.write(workdir.resolve("bar/one"), "First version".getBytes(UTF_8));
    Files.write(workdir.resolve("baz/one"), "First version".getBytes(UTF_8));
    repo().withWorkTree(workdir).add().files("foo/one").files("bar/one").files("baz/one").run();
    repo().withWorkTree(workdir).simpleCommand("commit", "-m", "Initial commit");
    Glob repoAglob = Glob.createGlob(ImmutableList.of("foo/**"), ImmutableList.of("bar/**"));
    Glob repoBglob = Glob.createGlob(ImmutableList.of("bar/**"), ImmutableList.of("foo/**"));
    // Change on repo A
    Files.write(workdir.resolve("foo/one"), "Second version".getBytes(UTF_8));
    Writer<GitRevision> writer1 = newWriter();
    DummyRevision repoAfirstRev = new DummyRevision("Foo first");
    process(writer1, repoAglob, repoAfirstRev);
    assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Second version").containsFile("bar/one", "First version").containsFile("baz/one", "First version").containsNoMoreFiles();
    verifyDestinationStatus(repoAglob, repoAfirstRev);
    // Change on repo B, does not affect repo A paths
    Files.write(workdir.resolve("bar/one"), "Second version".getBytes(UTF_8));
    Writer<GitRevision> writer2 = newWriter();
    DummyRevision repoBfirstRev = new DummyRevision("Bar first");
    process(writer2, repoBglob, repoBfirstRev);
    assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Second version").containsFile("bar/one", "Second version").containsFile("baz/one", "First version").containsNoMoreFiles();
    verifyDestinationStatus(repoAglob, repoAfirstRev);
    verifyDestinationStatus(repoBglob, repoBfirstRev);
    // Change on repo A does not affect repo B paths
    Files.write(workdir.resolve("foo/one"), "Third version".getBytes(UTF_8));
    Writer<GitRevision> writer3 = newWriter();
    DummyRevision repoASecondRev = new DummyRevision("Foo second");
    process(writer3, repoAglob, repoASecondRev);
    assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Third version").containsFile("bar/one", "Second version").containsFile("baz/one", "First version").containsNoMoreFiles();
    verifyDestinationStatus(repoAglob, repoASecondRev);
    verifyDestinationStatus(repoBglob, repoBfirstRev);
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) Glob(com.google.copybara.util.Glob) Test(org.junit.Test)

Example 35 with DummyRevision

use of com.google.copybara.testing.DummyRevision in project copybara by google.

the class GitDestinationTest method testDryRun.

@Test
public void testDryRun() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
    Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
    repo().withWorkTree(scratchTree).add().force().files("foo").run();
    repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
    WriterContext writerContext = new WriterContext("piper_to_github", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    Writer<GitRevision> writer = destination().newWriter(writerContext);
    process(writer, new DummyRevision("origin_ref1"));
    assertThatCheckout(repo(), primaryBranch).containsFile("foo", "foo\n").containsNoMoreFiles();
    // Run again without dry run
    writer = newWriter();
    process(writer, new DummyRevision("origin_ref1"));
    assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
}
Also used : Path(java.nio.file.Path) WriterContext(com.google.copybara.WriterContext) 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