Search in sources :

Example 1 with DiffInfo

use of com.google.gerrit.extensions.common.DiffInfo in project gerrit by GerritCodeReview.

the class ChangeEditIT method diff.

@Test
public void diff() throws Exception {
    createEmptyEditFor(changeId);
    gApi.changes().id(changeId).edit().modifyFile(FILE_NAME, RawInputUtil.create(CONTENT_NEW));
    Optional<EditInfo> edit = getEdit(changeId);
    assertThat(edit).isPresent();
    String editCommitId = edit.get().commit.commit;
    RestResponse r = adminRestSession.getJsonAccept(urlDiff(changeId, editCommitId, FILE_NAME));
    DiffInfo diff = readContentFromJson(r, DiffInfo.class);
    assertThat(diff.diffHeader.get(0)).contains(FILE_NAME);
    r = adminRestSession.getJsonAccept(urlDiff(changeId, FILE_NAME));
    diff = readContentFromJson(r, DiffInfo.class);
    assertThat(diff.diffHeader.get(0)).contains(FILE_NAME);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) EditInfo(com.google.gerrit.extensions.common.EditInfo) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with DiffInfo

use of com.google.gerrit.extensions.common.DiffInfo in project gerrit by GerritCodeReview.

the class RevisionIT method diffOnMergeCommitChange.

@Test
public void diffOnMergeCommitChange() throws Exception {
    PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
    DiffInfo diff;
    // automerge
    diff = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).file("foo").diff();
    assertThat(diff.metaA.lines).isEqualTo(5);
    assertThat(diff.metaB.lines).isEqualTo(1);
    diff = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).file("bar").diff();
    assertThat(diff.metaA.lines).isEqualTo(5);
    assertThat(diff.metaB.lines).isEqualTo(1);
    // parent 1
    diff = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).file("bar").diff(1);
    assertThat(diff.metaA.lines).isEqualTo(1);
    assertThat(diff.metaB.lines).isEqualTo(1);
    // parent 2
    diff = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).file("foo").diff(2);
    assertThat(diff.metaA.lines).isEqualTo(1);
    assertThat(diff.metaB.lines).isEqualTo(1);
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with DiffInfo

use of com.google.gerrit.extensions.common.DiffInfo in project gerrit by GerritCodeReview.

the class RevisionIT method assertDiffForNewFile.

private void assertDiffForNewFile(PushOneCommit.Result pushResult, String path, String expectedContentSideB) throws Exception {
    DiffInfo diff = gApi.changes().id(pushResult.getChangeId()).revision(pushResult.getCommit().name()).file(path).diff();
    List<String> headers = new ArrayList<>();
    if (path.equals(COMMIT_MSG)) {
        RevCommit c = pushResult.getCommit();
        RevCommit parentCommit = c.getParents()[0];
        String parentCommitId = testRepo.getRevWalk().getObjectReader().abbreviate(parentCommit.getId(), 8).name();
        headers.add("Parent:     " + parentCommitId + " (" + parentCommit.getShortMessage() + ")");
        SimpleDateFormat dtfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
        PersonIdent author = c.getAuthorIdent();
        dtfmt.setTimeZone(author.getTimeZone());
        headers.add("Author:     " + author.getName() + " <" + author.getEmailAddress() + ">");
        headers.add("AuthorDate: " + dtfmt.format(Long.valueOf(author.getWhen().getTime())));
        PersonIdent committer = c.getCommitterIdent();
        dtfmt.setTimeZone(committer.getTimeZone());
        headers.add("Commit:     " + committer.getName() + " <" + committer.getEmailAddress() + ">");
        headers.add("CommitDate: " + dtfmt.format(Long.valueOf(committer.getWhen().getTime())));
        headers.add("");
    }
    if (!headers.isEmpty()) {
        String header = Joiner.on("\n").join(headers);
        expectedContentSideB = header + "\n" + expectedContentSideB;
    }
    assertDiffForNewFile(diff, pushResult.getCommit(), path, expectedContentSideB);
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 4 with DiffInfo

use of com.google.gerrit.extensions.common.DiffInfo in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method assertDiffForNewFile.

protected void assertDiffForNewFile(DiffInfo diff, RevCommit commit, String path, String expectedContentSideB) throws Exception {
    List<String> expectedLines = new ArrayList<>();
    for (String line : expectedContentSideB.split("\n")) {
        expectedLines.add(line);
    }
    assertThat(diff.binary).isNull();
    assertThat(diff.changeType).isEqualTo(ChangeType.ADDED);
    assertThat(diff.diffHeader).isNotNull();
    assertThat(diff.intralineStatus).isNull();
    assertThat(diff.webLinks).isNull();
    assertThat(diff.metaA).isNull();
    assertThat(diff.metaB).isNotNull();
    assertThat(diff.metaB.commitId).isEqualTo(commit.name());
    String expectedContentType = "text/plain";
    if (COMMIT_MSG.equals(path)) {
        expectedContentType = FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE;
    } else if (MERGE_LIST.equals(path)) {
        expectedContentType = FileContentUtil.TEXT_X_GERRIT_MERGE_LIST;
    }
    assertThat(diff.metaB.contentType).isEqualTo(expectedContentType);
    assertThat(diff.metaB.lines).isEqualTo(expectedLines.size());
    assertThat(diff.metaB.name).isEqualTo(path);
    assertThat(diff.metaB.webLinks).isNull();
    assertThat(diff.content).hasSize(1);
    DiffInfo.ContentEntry contentEntry = diff.content.get(0);
    assertThat(contentEntry.b).containsExactlyElementsIn(expectedLines).inOrder();
    assertThat(contentEntry.a).isNull();
    assertThat(contentEntry.ab).isNull();
    assertThat(contentEntry.common).isNull();
    assertThat(contentEntry.editA).isNull();
    assertThat(contentEntry.editB).isNull();
    assertThat(contentEntry.skip).isNull();
}
Also used : ArrayList(java.util.ArrayList) IdString(com.google.gerrit.extensions.restapi.IdString) DiffInfo(com.google.gerrit.extensions.common.DiffInfo)

Example 5 with DiffInfo

use of com.google.gerrit.extensions.common.DiffInfo in project gerrit by GerritCodeReview.

the class MergeListIT method getDiffForMergeList.

@Test
public void getDiffForMergeList() throws Exception {
    DiffInfo diff = getMergeListDiff(changeId);
    assertDiffForNewFile(diff, merge, MERGE_LIST, getMergeListContent(parent2, grandParent2));
    diff = getMergeListDiff(changeId, 1);
    assertDiffForNewFile(diff, merge, MERGE_LIST, getMergeListContent(parent2, grandParent2));
    diff = getMergeListDiff(changeId, 2);
    assertDiffForNewFile(diff, merge, MERGE_LIST, getMergeListContent(parent1, grandParent1));
}
Also used : DiffInfo(com.google.gerrit.extensions.common.DiffInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

DiffInfo (com.google.gerrit.extensions.common.DiffInfo)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 Test (org.junit.Test)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 ArrayList (java.util.ArrayList)2 RestResponse (com.google.gerrit.acceptance.RestResponse)1 PatchScript (com.google.gerrit.common.data.PatchScript)1 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)1 FileMeta (com.google.gerrit.extensions.common.DiffInfo.FileMeta)1 DiffWebLinkInfo (com.google.gerrit.extensions.common.DiffWebLinkInfo)1 EditInfo (com.google.gerrit.extensions.common.EditInfo)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 SparseFileContent (com.google.gerrit.prettify.common.SparseFileContent)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 LargeObjectException (com.google.gerrit.server.git.LargeObjectException)1 PatchScriptFactory (com.google.gerrit.server.patch.PatchScriptFactory)1 NoSuchChangeException (com.google.gerrit.server.project.NoSuchChangeException)1 ProjectState (com.google.gerrit.server.project.ProjectState)1