Search in sources :

Example 6 with DummyRevision

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

the class WorkflowTest method skipNotesForExcludedFiles.

@Test
public void skipNotesForExcludedFiles() throws Exception {
    originFiles = "glob(['**'], exclude = ['foo'])";
    transformations = ImmutableList.of("metadata.squash_notes()");
    FileSystem fileSystem = Jimfs.newFileSystem();
    Path one = Files.createDirectories(fileSystem.getPath("one"));
    Path two = Files.createDirectories(fileSystem.getPath("two"));
    Path three = Files.createDirectories(fileSystem.getPath("three"));
    Path four = Files.createDirectories(fileSystem.getPath("four"));
    touchFile(one, "foo", "");
    touchFile(one, "bar", "");
    origin.addChange(1, one, "foo and bar", /*matchesGlob=*/
    true);
    touchFile(two, "foo", "a");
    touchFile(two, "bar", "");
    origin.addChange(2, two, "only foo", /*matchesGlob=*/
    true);
    touchFile(three, "foo", "a");
    touchFile(three, "bar", "a");
    origin.addChange(3, three, "only bar", /*matchesGlob=*/
    true);
    DummyRevision bar = origin.resolve(HEAD);
    touchFile(four, "foo", "b");
    touchFile(four, "bar", "a");
    origin.addChange(4, four, "foo again", /*matchesGlob=*/
    true);
    skylarkWorkflow("default", SQUASH).run(workdir, ImmutableList.of(HEAD));
    // We skip changes that only touch foo.
    assertThat(Iterables.getLast(destination.processed).getChangesSummary()).isEqualTo("Copybara import of the project:\n" + "\n" + "  - 2 only bar by Copybara <no-reply@google.com>\n" + "  - 0 foo and bar by Copybara <no-reply@google.com>\n");
    // We use as reference for the destination label the last change that affects
    // origin_files.
    assertThat(Iterables.getLast(destination.processed).getOriginRef().asString()).isEqualTo(bar.asString());
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) FileSystem(java.nio.file.FileSystem) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 7 with DummyRevision

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

the class WorkflowTest method squashReadsLatestAffectedChangeInRoot.

@Test
public void squashReadsLatestAffectedChangeInRoot() throws Exception {
    origin.addSimpleChange(/*timestamp*/
    1);
    transformations = ImmutableList.of();
    Workflow<?, ?> workflow = workflow();
    workflow.run(workdir, ImmutableList.of("HEAD"));
    origin.addSimpleChange(/*timestamp*/
    2);
    DummyRevision expected = origin.resolve("HEAD");
    origin.addChange(/*timestamp*/
    3, Paths.get("not important"), "message", /*matchesGlob=*/
    false);
    options.setForce(false);
    workflow = skylarkWorkflow("default", SQUASH);
    workflow.run(workdir, ImmutableList.of("HEAD"));
    ProcessedChange change = Iterables.getLast(destination.processed);
    assertThat(change.getOriginRef().asString()).isEqualTo(expected.asString());
}
Also used : ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 8 with DummyRevision

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

the class FolderDestinationTest method write.

private void write() throws ValidationException, RepoException, IOException {
    WriterContext writerContext = new WriterContext("FolderDestinationTest", "test", false, new DummyRevision("origin_ref"), Glob.ALL_FILES.roots());
    skylark.<Destination<Revision>>eval("dest", "dest = folder.destination()").newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("origin_ref")), Glob.createGlob(ImmutableList.of("**"), excludedPathsForDeletion), options.general.console());
}
Also used : WriterContext(com.google.copybara.WriterContext) Destination(com.google.copybara.Destination) DummyRevision(com.google.copybara.testing.DummyRevision)

Example 9 with DummyRevision

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

the class GerritDestinationTest method reuseChangeId.

@Test
public void reuseChangeId() throws Exception {
    fetch = "master";
    writeFile(workdir, "file", "some content");
    options.setForce(true);
    options.gerrit.gerritChangeId = null;
    url = "https://localhost:33333/foo/bar";
    GitRepository repo = gitUtil.mockRemoteRepo("localhost:33333/foo/bar");
    mockNoChangesFound();
    process(new DummyRevision("origin_ref"));
    String changeId = lastCommitChangeIdLine("origin_ref", repo);
    assertThat(changeId).matches(GerritDestination.CHANGE_ID_LABEL + ": I[a-z0-9]+");
    LabelFinder labelFinder = new LabelFinder(changeId);
    writeFile(workdir, "file", "some different content");
    String expected = "https://localhost:33333/changes/?q=hashtag:%22copybara_id_origin_ref_commiter@email%22" + "%20AND%20project:foo/bar%20AND%20status:NEW";
    gitUtil.mockApi("GET", expected, mockResponse("[" + "{" + "  change_id : \"" + labelFinder.getValue() + "\"," + "  status : \"NEW\"" + "}]"));
    // Allow to push again in a non-fastforward way.
    repo.simpleCommand("update-ref", "-d", getGerritRef(repo, "refs/for/master"));
    process(new DummyRevision("origin_ref"));
    assertThat(lastCommitChangeIdLine("origin_ref", repo)).isEqualTo(changeId);
    assertThatGerritCheckout(repo, "refs/for/master").containsFile("file", "some different content").containsNoMoreFiles();
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) LabelFinder(com.google.copybara.LabelFinder) Test(org.junit.Test)

Example 10 with DummyRevision

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

the class GerritDestinationTest method canExcludeDestinationPathFromWorkflow.

@Test
public void canExcludeDestinationPathFromWorkflow() throws Exception {
    fetch = repo().getPrimaryBranch();
    Path scratchWorkTree = Files.createTempDirectory("GitDestinationTest-scratchWorkTree");
    writeFile(scratchWorkTree, "excluded.txt", "some content");
    repo().withWorkTree(scratchWorkTree).add().files("excluded.txt").run();
    repo().withWorkTree(scratchWorkTree).simpleCommand("commit", "-m", "message");
    writeFile(workdir, "normal_file.txt", "some more content");
    excludedDestinationPaths = ImmutableList.of("excluded.txt");
    process(new DummyRevision("ref"));
    assertThatGerritCheckout(repo(), "refs/for/" + fetch).containsFile("excluded.txt", "some content").containsFile("normal_file.txt", "some more content").containsNoMoreFiles();
}
Also used : Path(java.nio.file.Path) FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) 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