use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method testVisit.
@Test
public void testVisit() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
DummyRevision ref1 = new DummyRevision("origin_ref1");
DummyRevision ref2 = new DummyRevision("origin_ref2");
Files.write(workdir.resolve("test.txt"), "Visit me".getBytes(UTF_8));
process(firstCommitWriter(), ref1);
Files.write(workdir.resolve("test.txt"), "Visit me soon".getBytes(UTF_8));
process(newWriter(), ref2);
List<Change<?>> visited = new ArrayList<>();
newWriter().visitChanges(null, input -> {
visited.add(input);
return input.getLabels().get(DummyOrigin.LABEL_NAME).contains("origin_ref1") ? VisitResult.TERMINATE : VisitResult.CONTINUE;
});
assertThat(visited).hasSize(2);
assertThat(visited.get(0).getLabels().get(DummyOrigin.LABEL_NAME)).containsExactly("origin_ref2");
assertThat(visited.get(1).getLabels().get(DummyOrigin.LABEL_NAME)).containsExactly("origin_ref1");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method testGitIgnoreExcluded.
@Test
public void testGitIgnoreExcluded() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
Path scratchTree = Files.createTempDirectory("GitDestinationTest-testGitIgnoreExcluded");
Files.write(scratchTree.resolve(".gitignore"), ".gitignore\n".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().force().files(".gitignore").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "gitignore file");
destinationFiles = Glob.createGlob(ImmutableList.of("**"), ImmutableList.of(".gitignore"));
DummyRevision ref = new DummyRevision("origin_ref");
process(newWriter(), ref);
assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsFile(".gitignore", ".gitignore\n").containsNoMoreFiles();
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method processWithBaselineSameFileConflict.
@Test
public void processWithBaselineSameFileConflict() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
DummyRevision ref = new DummyRevision("origin_ref");
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
process(firstCommitWriter(), ref);
String firstCommit = repo().parseRef("HEAD");
Files.write(workdir.resolve("test.txt"), "new content".getBytes(UTF_8));
process(newWriter(), ref);
Files.write(workdir.resolve("test.txt"), "conflict content".getBytes(UTF_8));
RebaseConflictException thrown = assertThrows(RebaseConflictException.class, () -> processWithBaseline(newWriter(), destinationFiles, ref, firstCommit));
assertThat(thrown).hasMessageThat().contains("conflict in test.txt");
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method multipleMigrationsToOneDestination_separateRoots.
/**
* Verify that multiple (exclusive) migrations can write to the same Git repository. This is,
* migrations from different origins writing to a different subpaths in the Git repo and excluding
* the other ones.
*/
@Test
public void multipleMigrationsToOneDestination_separateRoots() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.createDirectories(workdir.resolve("foo"));
Files.createDirectories(workdir.resolve("bar"));
Files.createDirectories(workdir.resolve("baz"));
Files.write(workdir.resolve("foo/one"), "First version".getBytes(UTF_8));
Files.write(workdir.resolve("bar/one"), "First version".getBytes(UTF_8));
Files.write(workdir.resolve("baz/one"), "First version".getBytes(UTF_8));
repo().withWorkTree(workdir).add().files("foo/one").files("bar/one").files("baz/one").run();
repo().withWorkTree(workdir).simpleCommand("commit", "-m", "Initial commit");
Glob repoAglob = Glob.createGlob(ImmutableList.of("foo/**"), ImmutableList.of("bar/**"));
Glob repoBglob = Glob.createGlob(ImmutableList.of("bar/**"), ImmutableList.of("foo/**"));
// Change on repo A
Files.write(workdir.resolve("foo/one"), "Second version".getBytes(UTF_8));
Writer<GitRevision> writer1 = newWriter();
DummyRevision repoAfirstRev = new DummyRevision("Foo first");
process(writer1, repoAglob, repoAfirstRev);
assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Second version").containsFile("bar/one", "First version").containsFile("baz/one", "First version").containsNoMoreFiles();
verifyDestinationStatus(repoAglob, repoAfirstRev);
// Change on repo B, does not affect repo A paths
Files.write(workdir.resolve("bar/one"), "Second version".getBytes(UTF_8));
Writer<GitRevision> writer2 = newWriter();
DummyRevision repoBfirstRev = new DummyRevision("Bar first");
process(writer2, repoBglob, repoBfirstRev);
assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Second version").containsFile("bar/one", "Second version").containsFile("baz/one", "First version").containsNoMoreFiles();
verifyDestinationStatus(repoAglob, repoAfirstRev);
verifyDestinationStatus(repoBglob, repoBfirstRev);
// Change on repo A does not affect repo B paths
Files.write(workdir.resolve("foo/one"), "Third version".getBytes(UTF_8));
Writer<GitRevision> writer3 = newWriter();
DummyRevision repoASecondRev = new DummyRevision("Foo second");
process(writer3, repoAglob, repoASecondRev);
assertThatCheckout(repo(), primaryBranch).containsFile("foo/one", "Third version").containsFile("bar/one", "Second version").containsFile("baz/one", "First version").containsNoMoreFiles();
verifyDestinationStatus(repoAglob, repoASecondRev);
verifyDestinationStatus(repoBglob, repoBfirstRev);
}
use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method testDryRun.
@Test
public void testDryRun() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
Path scratchTree = Files.createTempDirectory("GitDestinationTest-testLocalRepo");
Files.write(scratchTree.resolve("foo"), "foo\n".getBytes(UTF_8));
repo().withWorkTree(scratchTree).add().force().files("foo").run();
repo().withWorkTree(scratchTree).simpleCommand("commit", "-a", "-m", "change");
WriterContext writerContext = new WriterContext("piper_to_github", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destination().newWriter(writerContext);
process(writer, new DummyRevision("origin_ref1"));
assertThatCheckout(repo(), primaryBranch).containsFile("foo", "foo\n").containsNoMoreFiles();
// Run again without dry run
writer = newWriter();
process(writer, new DummyRevision("origin_ref1"));
assertThatCheckout(repo(), primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
}
Aggregations