Search in sources :

Example 26 with RepoException

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");
}
Also used : Path(java.nio.file.Path) Writer(com.google.copybara.Destination.Writer) GitTestUtil(com.google.copybara.testing.git.GitTestUtil) Iterables(com.google.common.collect.Iterables) DummyRevision(com.google.copybara.testing.DummyRevision) TransformResult(com.google.copybara.TransformResult) DummyOrigin(com.google.copybara.testing.DummyOrigin) RunWith(org.junit.runner.RunWith) RepoException(com.google.copybara.exception.RepoException) OptionsBuilder(com.google.copybara.testing.OptionsBuilder) MessageType(com.google.copybara.util.console.Message.MessageType) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Strategy(com.google.copybara.git.GitIntegrateChanges.Strategy) GitTestUtil.getGitEnv(com.google.copybara.testing.git.GitTestUtil.getGitEnv) CannotResolveRevisionException(com.google.copybara.exception.CannotResolveRevisionException) Assert.fail(org.junit.Assert.fail) GitTesting(com.google.copybara.git.testing.GitTesting) TransformResults(com.google.copybara.testing.TransformResults) Path(java.nio.file.Path) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) Files(java.nio.file.Files) TestGitOptions(com.google.copybara.testing.git.GitTestUtil.TestGitOptions) HttpTransport(com.google.api.client.http.HttpTransport) ValidationException(com.google.copybara.exception.ValidationException) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Glob(com.google.copybara.util.Glob) Rule(org.junit.Rule) Optional(java.util.Optional) INCLUDE_FILES(com.google.copybara.git.GitIntegrateChanges.Strategy.INCLUDE_FILES) FAKE_MERGE(com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE) Joiner(com.google.common.base.Joiner) GitLogEntry(com.google.copybara.git.GitRepository.GitLogEntry) Test(org.junit.Test)

Example 27 with RepoException

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.*");
}
Also used : RepoException(com.google.copybara.exception.RepoException) Test(org.junit.Test)

Example 28 with RepoException

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 ");
    }
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) GitApiMockHttpTransport(com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport) IOException(java.io.IOException) RepoException(com.google.copybara.exception.RepoException) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Test(org.junit.Test)

Aggregations

RepoException (com.google.copybara.exception.RepoException)28 IOException (java.io.IOException)14 ValidationException (com.google.copybara.exception.ValidationException)11 ImmutableList (com.google.common.collect.ImmutableList)8 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)8 Path (java.nio.file.Path)8 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)7 Before (org.junit.Before)7 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)6 TestGitOptions (com.google.copybara.testing.git.GitTestUtil.TestGitOptions)6 HttpTransport (com.google.api.client.http.HttpTransport)5 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)5 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)5 Glob (com.google.copybara.util.Glob)5 GenericUrl (com.google.api.client.http.GenericUrl)4 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)4 Iterables (com.google.common.collect.Iterables)4 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)4 DummyRevision (com.google.copybara.testing.DummyRevision)4 GitApiMockHttpTransport (com.google.copybara.testing.OptionsBuilder.GitApiMockHttpTransport)4