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