use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method testTagWithExistingAndWarningMsg.
@Test
public void testTagWithExistingAndWarningMsg() throws Exception {
WriterContext writerContext = setUpForTestingTag();
// push existing tag with tagMsg
evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")), destinationFiles, console);
CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
console.assertThat().onceInLog(MessageType.WARNING, ".*Tag " + tagName + " exists. To overwrite it please use flag '--git-tag-overwrite'.*");
assertThat(commandOutput.getStdout()).matches(".*" + tagName + ".*test summary\n" + ".*\n" + ".*DummyOrigin-RevId: ref2\n");
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method testTagWithMsg.
@Test
public void testTagWithMsg() 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);
options.setForce(false);
Changes changes = new Changes(ImmutableList.of(new Change<>(new DummyRevision("ref2"), new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345"))), ImmutableList.of());
Files.write(workdir.resolve("test.txt"), "some content 2".getBytes(UTF_8));
evalDestinationWithTag(tagMsg).newWriter(writerContext).write(TransformResults.of(workdir, new DummyRevision("ref2")).withChanges(changes), destinationFiles, console);
CommandOutput commandOutput = repo().simpleCommand("tag", "-n9");
assertThat(commandOutput.getStdout()).matches(".*test_v1.*" + tagMsg + "\n");
}
use of com.google.copybara.WriterContext 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();
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method lastRevOnlyForAffectedRoots.
@Test
public void lastRevOnlyForAffectedRoots() 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"), "content".getBytes(UTF_8));
Files.write(workdir.resolve("bar/one"), "content".getBytes(UTF_8));
Files.write(workdir.resolve("baz/one"), "content".getBytes(UTF_8));
DummyRevision ref1 = new DummyRevision("first");
Glob firstGlob = Glob.createGlob(ImmutableList.of("foo/**", "bar/**"));
WriterContext writerContext = new WriterContext("piper_to_github", "TEST", false, new DummyRevision("test"), Glob.ALL_FILES.roots());
Writer<GitRevision> writer = destinationFirstCommit().newWriter(writerContext);
process(writer, ref1);
Files.write(workdir.resolve("baz/one"), "content2".getBytes(UTF_8));
DummyRevision ref2 = new DummyRevision("second");
process(writer, Glob.createGlob(ImmutableList.of("baz/**")), ref2);
assertThat(destination().newWriter(writerContext).getDestinationStatus(firstGlob, DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo(ref1.asString());
assertThat(writer.getDestinationStatus(Glob.createGlob(ImmutableList.of("baz/**")), DummyOrigin.LABEL_NAME).getBaseline()).isEqualTo(ref2.asString());
}
use of com.google.copybara.WriterContext in project copybara by google.
the class GitDestinationTest method testChangeDescriptionEmpty_setRevId.
@Test
public void testChangeDescriptionEmpty_setRevId() 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("").withLabelFinder(s -> ImmutableList.of()).withSetRevId(false), Glob.createGlob(ImmutableList.of("**"), ImmutableList.of("test.txt")), console));
assertThat(e).hasMessageThat().contains("Change description is empty");
}
Aggregations