use of com.google.copybara.exception.RepoException in project copybara by google.
the class GitDestinationIntegrateTest method testGerritSemiFakeMerge.
@Test
public void testGerritSemiFakeMerge() throws ValidationException, IOException, RepoException {
Path workTree = Files.createTempDirectory("test");
GitRepository repo = fakeHttpsRepo("example.com/gerrit").withWorkTree(workTree);
String label = new GerritIntegrateLabel(repo, options.general, "https://example.com/gerrit", 1020, 1, CHANGE_ID).toString();
assertThat(label).isEqualTo("gerrit https://example.com/gerrit 1020 Patch Set 1 " + CHANGE_ID);
GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
GitRevision secondChange = singleChange(workTree, repo, "ignore_me2", "Feature2 change");
GitTestUtil.createFakeGerritNodeDbMeta(repo, 1020, CHANGE_ID);
repo.simpleCommand("update-ref", "refs/changes/20/1020/1", firstChange.getSha1());
repo.simpleCommand("update-ref", "refs/changes/20/1020/2", secondChange.getSha1());
GitDestination destination = destinationWithDefaultIntegrates();
GitLogEntry previous = createBaseDestinationChange(destination);
migrateOriginChange(destination, "Test change\n" + "\n" + GitModule.DEFAULT_INTEGRATE_LABEL + "=" + label + "\n", "some content");
// Make sure commit adds new text
String showResult = git("--git-dir", repoGitDir.toString(), "show", "master");
assertThat(showResult).contains("some content");
GitTesting.assertThatCheckout(repo(), "master").containsFile("test.txt", "some content").containsFile("ignore_me", "").containsNoMoreFiles();
GitLogEntry merge = getLastMigratedChange("master");
assertThat(merge.getBody()).isEqualTo("Merge Gerrit change 1020 Patch Set 1\n" + "\n" + "DummyOrigin-RevId: test\n" + "Change-Id: " + CHANGE_ID + "\n");
assertThat(Lists.transform(merge.getParents(), GitRevision::getSha1)).isEqualTo(Lists.newArrayList(previous.getCommit().getSha1(), firstChange.getSha1()));
assertThat(console.getMessages().stream().filter(e -> e.getType() == MessageType.WARNING).findAny().get().getText()).contains("Change 1020 has more patch sets after Patch Set 1." + " Latest is Patch Set 2. Not all changes might be migrated");
}
use of com.google.copybara.exception.RepoException in project copybara by google.
the class WorkflowTest method testIterativeRepoException.
@Test
public void testIterativeRepoException() throws Exception {
assertThat(checkIterativeModeWithError(new RepoException("Your change is wrong!"))).hasMessage("Your change is wrong!");
console().assertThat().onceInLog(MessageType.ERROR, "Migration of origin revision '2' failed with error: Your change is wrong.*");
}
use of com.google.copybara.exception.RepoException in project copybara by google.
the class GerritDestinationTest method changeAlreadyMergedTooOften.
@Test
public void changeAlreadyMergedTooOften() throws Exception {
fetch = "master";
Files.write(workdir.resolve("file"), "some content".getBytes());
options.setForce(true);
String firstChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", StandardCharsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(0).hash();
String secondChangeId = "I" + Hashing.sha1().newHasher().putString("origin_ref", Charsets.UTF_8).putString(options.gitDestination.committerEmail, StandardCharsets.UTF_8).putInt(1).hash();
gitApiMockHttpTransport = new GitApiMockHttpTransport() {
@Override
protected byte[] getContent(String method, String url, MockLowLevelHttpRequest request) throws IOException {
if (method.equals("GET") && url.startsWith("https://localhost:33333/changes/")) {
String change = changeIdFromRequest(url);
String result = "[" + "{" + " change_id : \"" + change + "\"," + " status : \"MERGED\"" + "}]";
return result.getBytes(UTF_8);
}
throw new IllegalArgumentException(method + " " + url);
}
};
try {
process(new DummyRevision("origin_ref"));
fail("Should have thrown RepoException");
} catch (RepoException expected) {
assertThat(expected.getMessage()).contains("Unable to find unmerged change for ");
}
}
Aggregations