Search in sources :

Example 11 with TransformResult

use of com.google.copybara.TransformResult 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 12 with TransformResult

use of com.google.copybara.TransformResult in project copybara by google.

the class GitDestinationTest method testLabelInSameLabelGroupGroup.

@Test
public void testLabelInSameLabelGroupGroup() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Writer<GitRevision> writer = firstCommitWriter();
    Files.write(workdir.resolve("test.txt"), "".getBytes(UTF_8));
    DummyRevision rev = new DummyRevision("first_commit");
    String msg = "This is a message\n" + "\n" + "That already has a label\n" + "THE_LABEL: value\n";
    writer.write(new TransformResult(workdir, rev, rev.getAuthor(), msg, rev, /*workflowName*/
    "default", TransformWorks.EMPTY_CHANGES, "first_commit", /*setRevId=*/
    true, ImmutableList::of, DummyOrigin.LABEL_NAME), destinationFiles, console);
    String body = lastCommit("HEAD").getBody();
    assertThat(body).isEqualTo("This is a message\n" + "\n" + "That already has a label\n" + "THE_LABEL: value\n" + "DummyOrigin-RevId: first_commit\n");
    // Double check that we can access it as a label.
    assertThat(ChangeMessage.parseMessage(body).labelsAsMultimap()).containsEntry("DummyOrigin-RevId", "first_commit");
}
Also used : TransformResult(com.google.copybara.TransformResult) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 13 with TransformResult

use of com.google.copybara.TransformResult in project copybara by google.

the class GitDestinationTest method testNoSetRevId.

@Test
public void testNoSetRevId() throws Exception {
    fetch = primaryBranch;
    push = primaryBranch;
    Files.write(workdir.resolve("test.txt"), "some content".getBytes(UTF_8));
    TransformResult result = TransformResults.of(workdir, new DummyRevision("origin_ref")).withSetRevId(false);
    ImmutableList<DestinationEffect> destinationResult = firstCommitWriter().write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(1);
    // Make sure commit adds new text
    String showResult = git("--git-dir", repoGitDir.toString(), "show", primaryBranch);
    assertThat(showResult).contains("some content");
    assertFilesInDir(1, primaryBranch, ".");
    assertCommitCount(1, primaryBranch);
    assertThat(parseMessage(lastCommit(primaryBranch).getBody()).labelsAsMultimap()).doesNotContainKey(DummyOrigin.LABEL_NAME);
}
Also used : TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Test(org.junit.Test)

Example 14 with TransformResult

use of com.google.copybara.TransformResult in project copybara by google.

the class GitHubDestinationTest method checkPrToUpdateWithRegularString.

private void checkPrToUpdateWithRegularString(String deletePrBranch, boolean expectDeletePrBranch) throws Exception {
    if (expectDeletePrBranch) {
        when(gitUtil.httpTransport().buildRequest(eq("DELETE"), contains("repos/foo/git/refs/heads/other"))).thenReturn(mockResponseWithStatus("", 204));
    }
    gitUtil.mockApi("GET", "https://api.github.com/repos/foo/git/refs/heads/other", mockResponse("{\n" + "\"ref\" : \"refs/heads/test_existing_pr\",\n" + "\"node_id\" : \"MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlQQ==\",\n" + "\"url\" :" + " \"https://api.github.com/repos/octocat/Hello-World/git/refs/heads/test_existing_pr\",\n" + "\"object\" : {\n" + "         \"type\" : \"commit\",\n" + "         \"sha\" : \"aa218f56b14c9653891f9e74264a383fa43fefbd\",\n" + "         \"url\" :" + " \"https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f56b14c9653891f9e74264a383fa43fefbd\"\n" + "       }\n" + "}"));
    addFiles(remote, primaryBranch, "first change", ImmutableMap.<String, String>builder().put("foo.txt", "foo").buildOrThrow());
    remote.simpleCommand("branch", "other");
    GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("foo.txt", "foo").containsNoMoreFiles();
    GitTesting.assertThatCheckout(remote, "other").containsFile("foo.txt", "foo").containsNoMoreFiles();
    WriterContext writerContext = new WriterContext("piper_to_github", "test", false, new DummyRevision("origin_ref1"), Glob.ALL_FILES.roots());
    writeFile(this.workdir, "test.txt", "some content");
    Writer<GitRevision> writer = destinationWithExistingPrBranch("other", deletePrBranch).newWriter(writerContext);
    DummyRevision ref = new DummyRevision("origin_ref1");
    TransformResult result = TransformResults.of(workdir, ref);
    Changes changes = new Changes(ImmutableList.of(new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "12345")), new Change<>(ref, new Author("foo", "foo@foo.com"), "message", ZonedDateTime.now(ZoneOffset.UTC), ImmutableListMultimap.of("my_label", "6789"))), ImmutableList.of());
    result = result.withChanges(changes);
    ImmutableList<DestinationEffect> destinationResult = writer.write(result, destinationFiles, console);
    assertThat(destinationResult).hasSize(expectDeletePrBranch ? 3 : 1);
    assertThat(destinationResult.get(0).getErrors()).isEmpty();
    assertThat(destinationResult.get(0).getType()).isEqualTo(Type.CREATED);
    assertThat(destinationResult.get(0).getDestinationRef().getType()).isEqualTo("commit");
    assertThat(destinationResult.get(0).getDestinationRef().getId()).matches("[0-9a-f]{40}");
    // This is a migration of two changes (use the same ref because mocks)
    verify(gitUtil.httpTransport(), times(expectDeletePrBranch ? 2 : 0)).buildRequest(eq("DELETE"), contains("refs/heads/other"));
    GitTesting.assertThatCheckout(remote, primaryBranch).containsFile("test.txt", "some content").containsNoMoreFiles();
    GitTesting.assertThatCheckout(remote, "other").containsFile("test.txt", "some content").containsNoMoreFiles();
}
Also used : Changes(com.google.copybara.Changes) WriterContext(com.google.copybara.WriterContext) TransformResult(com.google.copybara.TransformResult) DestinationEffect(com.google.copybara.DestinationEffect) DummyRevision(com.google.copybara.testing.DummyRevision) Author(com.google.copybara.authoring.Author) Change(com.google.copybara.Change)

Example 15 with TransformResult

use of com.google.copybara.TransformResult in project copybara by google.

the class HgDestinationTest method testWriteDeletesAndAddsFiles.

@Test
public void testWriteDeletesAndAddsFiles() throws Exception {
    Files.write(workdir.resolve("delete_me.txt"), "deleted content".getBytes(UTF_8));
    DummyRevision deletedRef = new DummyRevision("delete_ref");
    TransformResult result = TransformResults.of(workdir, deletedRef);
    writer.write(result, destinationFiles, console);
    workdir = options.general.getDirFactory().newTempDir("testWriteDeletesAndAddsFiles-workdir");
    Files.write(workdir.resolve("add_me.txt"), "added content".getBytes(UTF_8));
    createRevisionAndWrite("add_ref");
    remoteRepo.cleanUpdate("tip");
    ImmutableList<HgLogEntry> commits = remoteRepo.log().run();
    assertThat(commits).hasSize(3);
    assertThat(commits.get(0).getFiles()).hasSize(2);
    assertThat(commits.get(0).getFiles().get(0)).isEqualTo("add_me.txt");
    assertThat(commits.get(0).getFiles().get(1)).isEqualTo("delete_me.txt");
    assertThat(commits.get(1).getFiles()).hasSize(2);
    assertThat(commits.get(1).getFiles().get(0)).isEqualTo("delete_me.txt");
    assertThat(commits.get(1).getFiles().get(1)).isEqualTo("file.txt");
    assertThatPath(hgDestPath).containsFile("add_me.txt", "added content");
    assertThatPath(hgDestPath).containsNoFiles("delete_me.txt");
    assertThatPath(hgDestPath).containsNoFiles("file.txt");
}
Also used : TransformResult(com.google.copybara.TransformResult) DummyRevision(com.google.copybara.testing.DummyRevision) HgLogEntry(com.google.copybara.hg.HgRepository.HgLogEntry) Test(org.junit.Test)

Aggregations

TransformResult (com.google.copybara.TransformResult)16 DummyRevision (com.google.copybara.testing.DummyRevision)11 DestinationEffect (com.google.copybara.DestinationEffect)10 Test (org.junit.Test)8 Author (com.google.copybara.authoring.Author)5 Change (com.google.copybara.Change)4 Changes (com.google.copybara.Changes)4 WriterContext (com.google.copybara.WriterContext)4 ImmutableList (com.google.common.collect.ImmutableList)2 ChangeMessage (com.google.copybara.ChangeMessage)2 WriterImpl (com.google.copybara.git.GitDestination.WriterImpl)2 CreatePullRequest (com.google.copybara.git.github.api.CreatePullRequest)2 PullRequest (com.google.copybara.git.github.api.PullRequest)2 HgLogEntry (com.google.copybara.hg.HgRepository.HgLogEntry)2 Console (com.google.copybara.util.console.Console)2 CheckerException (com.google.copybara.checks.CheckerException)1 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 RepoException (com.google.copybara.exception.RepoException)1 GitHubApi (com.google.copybara.git.github.api.GitHubApi)1 GithubApi (com.google.copybara.git.github.api.GithubApi)1