use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method testTagWithLabel.
@Test
public void testTagWithLabel() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
tagName = "tag_${my_tag}";
tagMsg = "msg_${my_msg}";
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
options.setForce(true);
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
evalDestination().newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
options.setForce(false);
Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")).withLabelFinder(Functions.forMap(ImmutableMap.of("my_tag", ImmutableList.of("12345"), "my_msg", ImmutableList.of("2345")))), destinationFiles, console);
CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
assertThat(commandOutput.getStdout()).matches(".*tag_12345.*msg_2345\n");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method getDestinationStatusForFakeMergeAndNonEmptyRoots.
/**
* regression to ensure we don't do:
*
* git log -- some_path
*
* This doesn't work for fake merges as the merge is not shown when a path is passed even
* with -m.
*/
@Test
public void getDestinationStatusForFakeMergeAndNonEmptyRoots() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.createDirectories(workdir.resolve("dir"));
Files.write(workdir.resolve("dir/file"), "".getBytes(UTF_8));
GitRepository repo = repo().withWorkTree(workdir);
repo.add().files("dir/file").run();
repo.simpleCommand("commit", "-m", "first commit");
repo.simpleCommand("branch", "foo");
Files.write(workdir.resolve("dir/file"), "other".getBytes(UTF_8));
repo.add().files("dir/file").run();
repo.simpleCommand("commit", "-m", "first commit");
repo.forceCheckout("foo");
Files.write(workdir.resolve("dir/file"), "feature".getBytes(UTF_8));
repo.add().files("dir/file").run();
repo.simpleCommand("commit", "-m", "first commit");
repo.forceCheckout(primaryBranch);
// Fake merge
repo.simpleCommand("merge", "-Xours", "foo", "-m", "A fake merge\n\n" + DummyOrigin.LABEL_NAME + ": foo");
destinationFiles = Glob.createGlob(ImmutableList.of("dir/**"));
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("feature"), Glob.ALL_FILES.roots());
DestinationStatus status = destination().newWriter(writerContext).getDestinationStatus(destinationFiles, DummyOrigin.LABEL_NAME);
assertThat(status).isNotNull();
assertThat(status.getBaseline()).isEqualTo("foo");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method testChangeDescriptionEmpty.
@Test
public void testChangeDescriptionEmpty() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
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");
DummyRevision originRef = new DummyRevision("origin_ref");
WriterContext writerContext = new WriterContext("GitDestinationTest", "test", true, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destination().newWriter(writerContext);
ValidationException e = assertThrows(ValidationException.class, () -> writer.write(TransformResults.of(workdir, originRef).withSummary(" "), Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("test.txt")), console));
assertThat(e).hasMessageThat().contains("Change description is empty");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method setUpForTestingTag.
private WriterContext setUpForTestingTag() throws Exception {
fetch = primaryBranch;
push = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
options.setForce(true);
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
evalDestination().newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref1")), destinationFiles, console);
Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
// push tag without tagMsg
evalDestinationWithTag(null).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
Files.write(workdir.resolve("test.txt"), "some content 3".getBytes(UTF_8));
return writerContext;
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitHubDestinationTest method testPrToUpdateIngoredForInitHistory.
@Test
public void testPrToUpdateIngoredForInitHistory() throws Exception {
options.workflowOptions.initHistory = true;
addFiles(remote, primaryBranch, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "foo").buildOrThrow());
WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
writeFile(this.workdir, "test.txt", "some content");
Writer<GitRevision> writer = destinationWithExistingPrBranch("other", "True").newWriter(writerContext);
DummyRevision ref = new DummyRevision("origin_ref1");
TransformResult result = TransformResults.of(workdir, ref);
Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
result = result.withChanges(changes);
ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
assertThat(destinationResult).hasSize(1);
assertThat(destinationResult.get(0).getErrors()).isEmpty();
assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
// This is a migration of two changes (use the same ref because mocks)
verifyNoInteractions(gitUtil.httpTransport());
GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
assertThat(remote.simpleCommand("show-ref").getStdout()).doesNotContain("other");
}
Aggregations