Search in sources :

Example 1 with FileInfo

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

the class SubmittedTogetherIT method returnsCurrentFilesIfOptionRequested.

@Test
public void returnsCurrentFilesIfOptionRequested() throws Exception {
    RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();
    RevCommit c2_1 = commitBuilder().add("b.txt", "2").message("subject: 2").create();
    String id2 = getChangeId(c2_1);
    pushHead(testRepo, "refs/for/master", false);
    SubmittedTogetherInfo info = gApi.changes().id(id2).submittedTogether(EnumSet.of(ListChangesOption.CURRENT_FILES), EnumSet.of(NON_VISIBLE_CHANGES));
    assertThat(info.changes).hasSize(2);
    assertThat(info.changes.get(0).currentRevision).isEqualTo(c2_1.name());
    assertThat(info.changes.get(1).currentRevision).isEqualTo(c1_1.name());
    assertThat(info.changes.get(0).currentRevision).isEqualTo(c2_1.name());
    RevisionInfo rev = info.changes.get(0).revisions.get(c2_1.name());
    assertThat(rev).isNotNull();
    FileInfo file = rev.files.get("b.txt");
    assertThat(file).isNotNull();
    assertThat(file.status).isEqualTo('A');
}
Also used : RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) SubmittedTogetherInfo(com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with FileInfo

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

the class FileInfoJson method toFileInfoMap.

private Map<String, FileInfo> toFileInfoMap(Change change, PatchListKey key) throws PatchListNotAvailableException {
    PatchList list = patchListCache.get(key, change.getProject());
    Map<String, FileInfo> files = new TreeMap<>();
    for (PatchListEntry e : list.getPatches()) {
        FileInfo d = new FileInfo();
        d.status = e.getChangeType() != Patch.ChangeType.MODIFIED ? e.getChangeType().getCode() : null;
        d.oldPath = e.getOldName();
        d.sizeDelta = e.getSizeDelta();
        d.size = e.getSize();
        if (e.getPatchType() == Patch.PatchType.BINARY) {
            d.binary = true;
        } else {
            d.linesInserted = e.getInsertions() > 0 ? e.getInsertions() : null;
            d.linesDeleted = e.getDeletions() > 0 ? e.getDeletions() : null;
        }
        FileInfo o = files.put(e.getNewName(), d);
        if (o != null) {
            // This should only happen on a delete-add break created by JGit
            // when the file was rewritten and too little content survived. Write
            // a single record with data from both sides.
            d.status = Patch.ChangeType.REWRITE.getCode();
            d.sizeDelta = o.sizeDelta;
            d.size = o.size;
            if (o.binary != null && o.binary) {
                d.binary = true;
            }
            if (o.linesInserted != null) {
                d.linesInserted = o.linesInserted;
            }
            if (o.linesDeleted != null) {
                d.linesDeleted = o.linesDeleted;
            }
        }
    }
    return files;
}
Also used : PatchList(com.google.gerrit.server.patch.PatchList) FileInfo(com.google.gerrit.extensions.common.FileInfo) PatchListEntry(com.google.gerrit.server.patch.PatchListEntry) TreeMap(java.util.TreeMap)

Example 3 with FileInfo

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

the class ChangeEditIT method files.

@Test
public void files() 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(urlRevisionFiles(changeId, editCommitId));
    Map<String, FileInfo> files = readContentFromJson(r, new TypeToken<Map<String, FileInfo>>() {
    });
    assertThat(files).containsKey(FILE_NAME);
    r = adminRestSession.getJsonAccept(urlRevisionFiles(changeId));
    files = readContentFromJson(r, new TypeToken<Map<String, FileInfo>>() {
    });
    assertThat(files).containsKey(FILE_NAME);
}
Also used : FileInfo(com.google.gerrit.extensions.common.FileInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) EditInfo(com.google.gerrit.extensions.common.EditInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with FileInfo

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

the class RevisionIT method cherryPickMergeRelativeToSpecificParent.

@Test
public void cherryPickMergeRelativeToSpecificParent() throws Exception {
    String parent1FileName = "a.txt";
    String parent2FileName = "b.txt";
    PushOneCommit.Result mergeChangeResult = createCherryPickableMerge(parent1FileName, parent2FileName);
    String cherryPickBranchName = "branch_for_cherry_pick";
    createBranch(new Branch.NameKey(project, cherryPickBranchName));
    CherryPickInput cherryPickInput = new CherryPickInput();
    cherryPickInput.destination = cherryPickBranchName;
    cherryPickInput.message = "Cherry-pick a merge commit to another branch";
    cherryPickInput.parent = 2;
    ChangeInfo cherryPickedChangeInfo = gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput).get();
    Map<String, FileInfo> cherryPickedFilesByName = cherryPickedChangeInfo.revisions.get(cherryPickedChangeInfo.currentRevision).files;
    assertThat(cherryPickedFilesByName).containsKey(parent1FileName);
    assertThat(cherryPickedFilesByName).doesNotContainKey(parent2FileName);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) Branch(com.google.gerrit.reviewdb.client.Branch) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) NameKey(com.google.gerrit.reviewdb.client.Branch.NameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with FileInfo

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

the class RevisionIT method cherryPickMergeRelativeToDefaultParent.

@Test
public void cherryPickMergeRelativeToDefaultParent() throws Exception {
    String parent1FileName = "a.txt";
    String parent2FileName = "b.txt";
    PushOneCommit.Result mergeChangeResult = createCherryPickableMerge(parent1FileName, parent2FileName);
    String cherryPickBranchName = "branch_for_cherry_pick";
    createBranch(new Branch.NameKey(project, cherryPickBranchName));
    CherryPickInput cherryPickInput = new CherryPickInput();
    cherryPickInput.destination = cherryPickBranchName;
    cherryPickInput.message = "Cherry-pick a merge commit to another branch";
    ChangeInfo cherryPickedChangeInfo = gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput).get();
    Map<String, FileInfo> cherryPickedFilesByName = cherryPickedChangeInfo.revisions.get(cherryPickedChangeInfo.currentRevision).files;
    assertThat(cherryPickedFilesByName).containsKey(parent2FileName);
    assertThat(cherryPickedFilesByName).doesNotContainKey(parent1FileName);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) Branch(com.google.gerrit.reviewdb.client.Branch) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) NameKey(com.google.gerrit.reviewdb.client.Branch.NameKey) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

FileInfo (com.google.gerrit.extensions.common.FileInfo)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 Test (org.junit.Test)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)2 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)2 Branch (com.google.gerrit.reviewdb.client.Branch)2 NameKey (com.google.gerrit.reviewdb.client.Branch.NameKey)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 RestResponse (com.google.gerrit.acceptance.RestResponse)1 SubmittedTogetherInfo (com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo)1 EditInfo (com.google.gerrit.extensions.common.EditInfo)1 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)1 PatchList (com.google.gerrit.server.patch.PatchList)1 PatchListEntry (com.google.gerrit.server.patch.PatchListEntry)1 TypeToken (com.google.gson.reflect.TypeToken)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1