Search in sources :

Example 1 with Revision

use of com.google.copybara.Revision in project copybara by google.

the class GitOriginTest method partialFetch_canFetchRootFile.

@Test
public void partialFetch_canFetchRootFile() throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    Files.write(remote.resolve("file.txt"), new byte[0]);
    git("add", "file.txt");
    git("commit", "-m", "message");
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['directory/**', 'file.txt']),\n" + "    destination = testing.destination(),\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
    List<ProcessedChange> changes = destination.processed;
    assertThat(changes).hasSize(1);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 2 with Revision

use of com.google.copybara.Revision in project copybara by google.

the class GitOriginTest method partialFetchAtGitOrigin.

@Test
public void partialFetchAtGitOrigin() throws Exception {
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
    git("add", "include/fileA.txt");
    git("commit", "-m", "not include");
    git("checkout", defaultBranch);
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
    git("add", "include/mainline-file.txt");
    git("commit", "-m", "message_a!");
    options.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['include/mainline-file.txt']),\n" + "    destination = testing.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
    List<ProcessedChange> changes = destination.processed;
    assertThat(changes).hasSize(1);
    assertThat(changes.get(0).getChangesSummary()).contains("message_a!");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 3 with Revision

use of com.google.copybara.Revision in project copybara by google.

the class GitOriginTest method partialFetchFailsWithFetchingTheWholeRepo.

@Test
public void partialFetchFailsWithFetchingTheWholeRepo() throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         include_branch_commit_logs = True,\n" + "         partial_fetch = True,\n" + "    ),\n" + "    origin_files = glob(['**']),\n" + "    destination = testing.destination(),\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    ValidationException repoException = assertThrows(ValidationException.class, () -> wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD")));
    assertThat(repoException).hasMessageThat().contains("Config error: partial_fetch feature is not compatible with fetching the whole repo.");
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ValidationException(com.google.copybara.exception.ValidationException) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Example 4 with Revision

use of com.google.copybara.Revision in project copybara by google.

the class GitOriginTest method checkChangesMergeNoop.

@SuppressWarnings("unchecked")
private ImmutableList<? extends Change<?>> checkChangesMergeNoop(boolean importNoopChanges) throws Exception {
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    String author = "John Name <john@name.com>";
    singleFileCommit(author, "base", "base.txt", "");
    options.setLastRevision(repo.parseRef(defaultBranch));
    // Don't remove or add an include change before this commit. This allow us to test that we
    // traverse parents and not children:
    singleFileCommit(author, "exclude1", "exclude1", "");
    git("branch", "feature1");
    git("branch", "feature2");
    singleFileCommit(author, "main_branch_change", "one.txt", "");
    // Make sure one_change is shown before in git log.
    Thread.sleep(1100);
    git("checkout", "feature1");
    singleFileCommit(author, "feature1", "feature1.txt", "");
    git("checkout", defaultBranch);
    git("merge", defaultBranch, "feature1");
    String feature1Merge = repo.parseRef(defaultBranch);
    // Make sure one_change is shown before in git log.
    Thread.sleep(1100);
    git("checkout", "feature2");
    singleFileCommit(author, "change1", "base.txt", "base");
    // Revert
    singleFileCommit(author, "change2", "base.txt", "");
    singleFileCommit(author, "change3", "exclude.txt", "I should be excluded");
    git("checkout", defaultBranch);
    git("merge", defaultBranch, "feature2");
    String headSha1 = repo.parseRef(defaultBranch);
    Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + "         url = '" + url + "',\n" + "         first_parent = False,\n" + "    ),\n" + "    origin_files = glob(['**'], exclude = ['exclude**']),\n" + "    destination = testing.destination(),\n" + "    migrate_noop_changes = " + (importNoopChanges ? "True" : "False") + ",\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(checkoutDir, ImmutableList.of(defaultBranch));
    String expected = importNoopChanges ? headSha1 : feature1Merge;
    String actual = Iterables.getLast(destination.processed).getOriginRef().asString();
    assertWithMessage(String.format("Expected:\n%s\nBut found:\n%s", Iterables.getOnlyElement(repo.log(expected).withLimit(1).run()), Iterables.getOnlyElement(repo.log(actual).withLimit(1).run()))).that(actual).isEqualTo(expected);
    return Iterables.getLast(destination.processed).getOriginChanges();
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow)

Example 5 with Revision

use of com.google.copybara.Revision in project copybara by google.

the class GitOriginTest method autoDetectBranchAtGitOrigin.

@Test
public void autoDetectBranchAtGitOrigin() throws Exception {
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/fileA.txt"), new byte[0]);
    git("add", "include/fileA.txt");
    git("commit", "-m", "not include");
    defaultBranch = repo.getPrimaryBranch(url);
    git("checkout", defaultBranch);
    Files.createDirectories(remote.resolve("include"));
    Files.write(remote.resolve("include/mainline-file.txt"), new byte[0]);
    git("add", "include/mainline-file.txt");
    git("commit", "-m", "message_a!");
    options.setForce(true);
    RecordsProcessCallDestination destination = new RecordsProcessCallDestination();
    options.testingOptions.destination = destination;
    options.setLastRevision(firstCommitRef);
    @SuppressWarnings("unchecked") Workflow<GitRevision, Revision> wf = (Workflow<GitRevision, Revision>) skylark.loadConfig("" + "core.workflow(\n" + "    name = 'default',\n" + "    origin = git.origin(\n" + // Intentionally pick the "wrong" ref.
    "         ref = '" + (defaultBranch.equals("master") ? "main" : "master") + "',\n" + "         url = '" + url + "',\n" + "         primary_branch_migration = True,\n" + "    ),\n" + "    origin_files = glob(['include/mainline-file.txt']),\n" + "    destination = testing.destination(),\n" + "    mode = 'ITERATIVE',\n" + "    authoring = authoring.pass_thru('example <example@example.com>'),\n" + ")\n").getMigration("default");
    wf.run(Files.createTempDirectory("foo"), ImmutableList.of("HEAD"));
    List<ProcessedChange> changes = destination.processed;
    assertThat(changes).hasSize(1);
}
Also used : RecordsProcessCallDestination(com.google.copybara.testing.RecordsProcessCallDestination) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Revision(com.google.copybara.Revision) Workflow(com.google.copybara.Workflow) Test(org.junit.Test)

Aggregations

Revision (com.google.copybara.Revision)6 Workflow (com.google.copybara.Workflow)6 RecordsProcessCallDestination (com.google.copybara.testing.RecordsProcessCallDestination)6 Test (org.junit.Test)5 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)4 ValidationException (com.google.copybara.exception.ValidationException)1