Search in sources :

Example 1 with FAKE_MERGE

use of com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE in project copybara by google.

the class GitDestinationIntegrateTest method testGerritFakeMergeNoChangeId.

@Test
public void testGerritFakeMergeNoChangeId() 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, /*changeId=*/
    null).toString();
    assertThat(label).isEqualTo("gerrit https://example.com/gerrit 1020 Patch Set 1");
    GitRevision firstChange = singleChange(workTree, repo, "ignore_me", "Feature1 change");
    repo.simpleCommand("update-ref", "refs/changes/20/1020/1", firstChange.getSha1());
    GitTestUtil.createFakeGerritNodeDbMeta(repo, 1020, CHANGE_ID);
    GitDestination destination = destination(FAKE_MERGE);
    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").containsNoMoreFiles();
    GitLogEntry merge = getLastMigratedChange("master");
    assertThat(merge.getBody()).isEqualTo("Merge Gerrit change 1020 Patch Set 1\n" + "\n" + "DummyOrigin-RevId: test\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()).isEqualTo(Optional.empty());
}
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)

Aggregations

HttpTransport (com.google.api.client.http.HttpTransport)1 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Writer (com.google.copybara.Destination.Writer)1 TransformResult (com.google.copybara.TransformResult)1 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)1 RepoException (com.google.copybara.exception.RepoException)1 ValidationException (com.google.copybara.exception.ValidationException)1 Strategy (com.google.copybara.git.GitIntegrateChanges.Strategy)1 FAKE_MERGE (com.google.copybara.git.GitIntegrateChanges.Strategy.FAKE_MERGE)1 INCLUDE_FILES (com.google.copybara.git.GitIntegrateChanges.Strategy.INCLUDE_FILES)1 GitLogEntry (com.google.copybara.git.GitRepository.GitLogEntry)1 GitTesting (com.google.copybara.git.testing.GitTesting)1 DummyOrigin (com.google.copybara.testing.DummyOrigin)1 DummyRevision (com.google.copybara.testing.DummyRevision)1 OptionsBuilder (com.google.copybara.testing.OptionsBuilder)1 SkylarkTestExecutor (com.google.copybara.testing.SkylarkTestExecutor)1