use of com.google.copybara.Workflow 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);
}
use of com.google.copybara.Workflow 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!");
}
use of com.google.copybara.Workflow 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.");
}
use of com.google.copybara.Workflow 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();
}
use of com.google.copybara.Workflow in project copybara by google.
the class MetadataModuleTest method testMapAuthor.
@Test
public void testMapAuthor() throws Exception {
options.setLastRevision(origin.resolve("HEAD").asString());
Workflow wf = createWorkflow(WorkflowMode.ITERATIVE, MetadataModule.MAP_AUTHOR_EXAMPLE_SIMPLE);
origin.setAuthor(new Author("john", "john@example.com")).addSimpleChange(0, "change 0");
origin.setAuthor(new Author("Example Example", "madeupexample@google.com")).addSimpleChange(1, "change 1");
origin.setAuthor(new Author("John Example", "john.example@example.com")).addSimpleChange(2, "change 2");
origin.setAuthor(new Author("Other Example", "john.example@example.com")).addSimpleChange(3, "change 3");
origin.setAuthor(new Author("John Example", "other.example@example.com")).addSimpleChange(4, "change 4");
destination.processed.clear();
wf.run(workdir, /*sourceRef=*/
null);
assertThat(destination.processed.get(0).getAuthor().toString()).isEqualTo("Some Person <some@example.com>");
assertThat(destination.processed.get(1).getAuthor().toString()).isEqualTo("Other Person <someone@example.com>");
assertThat(destination.processed.get(2).getAuthor().toString()).isEqualTo("Another Person <some@email.com>");
assertThat(destination.processed.get(3).getAuthor().toString()).isEqualTo(// No match
"Other Example <john.example@example.com>");
assertThat(destination.processed.get(4).getAuthor().toString()).isEqualTo(// No match
"John Example <other.example@example.com>");
}
Aggregations