Search in sources :

Example 36 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitDestinationTest method emptyRebaseEmptyDescription.

@Test
public void emptyRebaseEmptyDescription() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    GitRepository destRepo = repo().withWorkTree(workdir);
    writeFile(workdir, "foo", "");
    destRepo.add().files("foo").run();
    destRepo.simpleCommand("commit", "-m", "baseline");
    GitRevision baseline = destRepo.resolveReference("HEAD");
    writeFile(workdir, "foo", "updated");
    destRepo.add().files("foo").run();
    destRepo.simpleCommand("commit", "-m", "primary head");
    writeFile(workdir, "foo", "updated");
    destinationFiles = Glob.createGlob(ImmutableList.of("foo"));
    TransformResult result = TransformResults.of(workdir, new DummyRevision("origin_ref")).withBaseline(baseline.getSha1()).withSummary("Empty");
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> {
        ImmutableList<DestinationEffect> destinationResult = newWriter().write(result, destinationFiles, console);
    });
    assertThat(e).hasMessageThat().contains("Empty change after rebase");
}
Also used : TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 37 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitDestinationTest method emptyRebaseTest.

@Test
public void emptyRebaseTest() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    GitRepository destRepo = repo().withWorkTree(workdir);
    writeFile(workdir, "foo", "");
    destRepo.add().files("foo").run();
    destRepo.simpleCommand("commit", "-m", "baseline");
    GitRevision baseline = destRepo.resolveReference("HEAD");
    writeFile(workdir, "foo", "updated");
    destRepo.add().files("foo").run();
    destRepo.simpleCommand("commit", "-m", "main head");
    writeFile(workdir, "foo", "updated");
    destinationFiles = Glob.createGlob(ImmutableList.of("foo"));
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> processWithBaseline(newWriter(), destinationFiles, new DummyRevision("origin_ref"), baseline.getSha1()));
    assertThat(e).hasMessageThat().contains("Empty change after rebase");
}
Also used : DummyRevision(com.google.copybara.testing.DummyRevision) EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 38 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method testLimitByBranch.

@Test
public void testLimitByBranch() throws Exception {
    // This should work since it returns a PR for main.
    MockPullRequest.create(gitUtil).setState("open").setPrNumber(125).addLabels("bar: yes").mock();
    checkResolve(githubPrOrigin("url = 'https://github.com/google/example'", "branch = 'main'"), "125", 125);
    MockPullRequest.create(gitUtil).setState("open").setPrNumber(126).addLabels("bar: yes").mock();
    EmptyChangeException e = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example'", "branch = 'other'"), "126", 126));
    assertThat(e).hasMessageThat().contains("because its base branch is 'main', but the workflow is configured to only migrate" + " changes for branch 'other'");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 39 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method testGitResolveRequiredLabelsNotRetryable.

@Test
public void testGitResolveRequiredLabelsNotRetryable() throws Exception {
    MockPullRequest.create(gitUtil).setState("open").setPrNumber(125).mock();
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example'", "required_labels = ['foo: yes']"), "125", 125));
    assertThat(thrown).hasMessageThat().contains("Cannot migrate http://github.com/google/example/pull/125 because it is missing the" + " following labels: [foo: yes]");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Example 40 with EmptyChangeException

use of com.google.copybara.exception.EmptyChangeException in project copybara by google.

the class GitHubPrOriginTest method testAlreadyClosed_default.

@Test
public void testAlreadyClosed_default() throws Exception {
    MockPullRequest.create(gitUtil).setState("closed").setPrNumber(125).addLabels("foo: yes").mock();
    EmptyChangeException thrown = assertThrows(EmptyChangeException.class, () -> checkResolve(githubPrOrigin("url = 'https://github.com/google/example'"), "125", 125));
    assertThat(thrown).hasMessageThat().contains("Pull Request 125 is closed");
}
Also used : EmptyChangeException(com.google.copybara.exception.EmptyChangeException) Test(org.junit.Test)

Aggregations

EmptyChangeException (com.google.copybara.exception.EmptyChangeException)42 Test (org.junit.Test)27 ImmutableList (com.google.common.collect.ImmutableList)10 RepoException (com.google.copybara.exception.RepoException)10 ValidationException (com.google.copybara.exception.ValidationException)10 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)10 Path (java.nio.file.Path)10 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)8 Endpoint (com.google.copybara.Endpoint)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 CharMatcher (com.google.common.base.CharMatcher)5 Preconditions (com.google.common.base.Preconditions)5 Splitter (com.google.common.base.Splitter)5 Collections2 (com.google.common.collect.Collections2)5 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)5 Iterables (com.google.common.collect.Iterables)5 Sets (com.google.common.collect.Sets)5 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)5 BaselinesWithoutLabelVisitor (com.google.copybara.BaselinesWithoutLabelVisitor)5 Change (com.google.copybara.Change)5