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);
}
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!");
}
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.");
}
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();
}
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);
}
Aggregations