use of com.google.copybara.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method processWithBaselineNotFound.
@Test
public void processWithBaselineNotFound() 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);
Files.write(workdir.resolve("test.txt"), "more content".getBytes(UTF_8));
RepoException thrown = assertThrows(RepoException.class, () -> processWithBaseline(newWriter(), destinationFiles, ref, "I_dont_exist"));
assertThat(thrown).hasMessageThat().contains("Cannot find baseline 'I_dont_exist' from fetch reference '");
}
use of com.google.copybara.testing.DummyRevision 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.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method checkLocalRepo.
private GitRepository checkLocalRepo(boolean dryRun) 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");
String baseline = repo().withWorkTree(scratchTree).simpleCommand("rev-parse", "HEAD").getStdout().trim();
Path localPath = Files.createTempDirectory("local_repo");
options.gitDestination.localRepoPath = localPath.toString();
Writer<GitRevision> writer = newWriter(dryRun);
process(writer, new DummyRevision("origin_ref1"));
// Path localPath = Files.createTempDirectory("local_repo");
GitRepository localRepo = GitRepository.newRepo(/*verbose*/
true, localPath, getEnv()).init();
assertThatCheckout(localRepo, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
Files.write(workdir.resolve("test.txt"), "another content".getBytes(UTF_8));
processWithBaseline(writer, destinationFiles, new DummyRevision("origin_ref2"), baseline);
assertThatCheckout(localRepo, primaryBranch).containsFile("test.txt", "another content").containsNoMoreFiles();
for (String ref : ImmutableList.of("HEAD", "copybara/local")) {
ImmutableList<GitLogEntry> entries = localRepo.log(ref).run();
assertThat(entries.get(0).getBody()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref2\n");
assertThat(entries.get(1).getBody()).isEqualTo("" + "test summary\n" + "\n" + "DummyOrigin-RevId: origin_ref1\n");
assertThat(entries.get(2).getBody()).isEqualTo("change\n");
}
return localRepo;
}
use of com.google.copybara.testing.DummyRevision 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.testing.DummyRevision in project copybara by google.
the class GitDestinationTest method process_autoDetect.
@Test
public void process_autoDetect() throws Exception {
push = primaryBranch;
fetch = primaryBranch;
Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
process(firstCommitWriter(), new DummyRevision("origin_ref"));
Files.write(workdir.resolve("test.txt"), "other content".getBytes(UTF_8));
primaryBranchMigration = "True";
push = "master";
fetch = "master";
// primaryBranch = repo().getPrimaryBranch(url);
process(newWriter(), new DummyRevision("process_autoDetect"));
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
assertThat(showResult).contains("other content");
assertFilesInDir(1, primaryBranch, ".");
assertCommitCount(2, primaryBranch);
assertCommitHasOrigin(primaryBranch, "process_autoDetect");
}
Aggregations