Search in sources :

Example 76 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PortedCommentsIT method commentOnFirstParentIsPortedToNewPosition.

@Test
public void commentOnFirstParentIsPortedToNewPosition() throws Exception {
    // Set up change and patchsets.
    Change.Id parent1ChangeId = changeOps.newChange().file("file1").content("Line 1\n").create();
    Change.Id parent2ChangeId = changeOps.newChange().file("file2").content("Line 1\n").create();
    Change.Id childChangeId = changeOps.newChange().mergeOf().change(parent1ChangeId).and().change(parent2ChangeId).file("file1").content("Line one\n").create();
    PatchSet.Id childPatchset1Id = changeOps.change(childChangeId).currentPatchset().get().patchsetId();
    PatchSet.Id parent1Patchset2Id = changeOps.change(parent1ChangeId).newPatchset().file("file1").content("Line 0\nLine 1\n").create();
    PatchSet.Id childPatchset2Id = changeOps.change(childChangeId).newPatchset().parents().patchset(parent1Patchset2Id).and().change(parent2ChangeId).create();
    // Add comment.
    String commentUuid = newComment(childPatchset1Id).onParentCommit().onLine(1).ofFile("file1").create();
    CommentInfo portedComment = getPortedComment(childPatchset2Id, commentUuid);
    assertThat(portedComment).line().isEqualTo(2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 77 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedCommentHasOriginalPatchset.

@Test
public void portedCommentHasOriginalPatchset() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).patchSet().isEqualTo(patchset1Id.get());
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 78 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PortedCommentsIT method commentOnSecondParentIsPortedToNewPosition.

@Test
public void commentOnSecondParentIsPortedToNewPosition() throws Exception {
    // Set up change and patchsets.
    Change.Id parent1ChangeId = changeOps.newChange().file("file1").content("Line 1\n").create();
    Change.Id parent2ChangeId = changeOps.newChange().file("file2").content("Line 1\n").create();
    Change.Id childChangeId = changeOps.newChange().mergeOf().change(parent1ChangeId).and().change(parent2ChangeId).file("file2").content("Line one\n").create();
    PatchSet.Id childPatchset1Id = changeOps.change(childChangeId).currentPatchset().get().patchsetId();
    PatchSet.Id parent2Patchset2Id = changeOps.change(parent1ChangeId).newPatchset().file("file2").content("Line 0\nLine 1\n").create();
    PatchSet.Id childPatchset2Id = changeOps.change(childChangeId).newPatchset().parents().change(parent1ChangeId).and().patchset(parent2Patchset2Id).create();
    // Add comment.
    String commentUuid = newComment(childPatchset1Id).onSecondParentCommit().onLine(1).ofFile("file2").create();
    CommentInfo portedComment = getPortedComment(childPatchset2Id, commentUuid);
    assertThat(portedComment).line().isEqualTo(2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 79 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PortedCommentsIT method commentOnFirstParentIsPortedToSingleParentWhenPatchsetChangedToNonMergeCommit.

@Test
public void commentOnFirstParentIsPortedToSingleParentWhenPatchsetChangedToNonMergeCommit() throws Exception {
    // Set up change and patchsets.
    Change.Id parent1ChangeId = changeOps.newChange().file("file1").content("Line 1\n").create();
    Change.Id parent2ChangeId = changeOps.newChange().file("file2").content("Line 1\n").create();
    Change.Id childChangeId = changeOps.newChange().mergeOf().change(parent1ChangeId).and().change(parent2ChangeId).create();
    PatchSet.Id childPatchset1Id = changeOps.change(childChangeId).currentPatchset().get().patchsetId();
    PatchSet.Id parent1PatchsetId2 = changeOps.change(parent1ChangeId).newPatchset().file("file1").content("Line 0\nLine 1\n").create();
    PatchSet.Id childPatchset2Id = changeOps.change(childChangeId).newPatchset().parent().patchset(parent1PatchsetId2).create();
    // Add comment.
    String commentUuid = newComment(childPatchset1Id).onParentCommit().onLine(1).ofFile("file1").create();
    CommentInfo portedComment = getPortedComment(childPatchset2Id, commentUuid);
    assertThat(portedComment).line().isEqualTo(2);
    assertThat(portedComment).side().isEqualTo(Side.PARENT);
    assertThat(portedComment).parent().isEqualTo(1);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 80 with PatchSet

use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.

the class PortedCommentsIT method commentOnAutoMergeCommitIsPortedToNewPosition.

@Test
public void commentOnAutoMergeCommitIsPortedToNewPosition() throws Exception {
    // Set up change and patchsets. Use the same file so that there's a meaningful auto-merge
    // commit/diff.
    Change.Id parent1ChangeId = changeOps.newChange().file("file1").content("Line 1\n").create();
    Change.Id parent2ChangeId = changeOps.newChange().file("file1").content("Line 1\n").create();
    Change.Id childChangeId = changeOps.newChange().mergeOf().change(parent1ChangeId).and().change(parent2ChangeId).create();
    PatchSet.Id childPatchset1Id = changeOps.change(childChangeId).currentPatchset().get().patchsetId();
    PatchSet.Id parent1Patchset2Id = changeOps.change(parent1ChangeId).newPatchset().file("file1").content("Line 0\nLine 1\n").create();
    PatchSet.Id parent2Patchset2Id = changeOps.change(parent1ChangeId).newPatchset().file("file1").content("Line zero\nLine 1\n").create();
    PatchSet.Id childPatchset2Id = changeOps.change(childChangeId).newPatchset().parents().patchset(parent1Patchset2Id).and().patchset(parent2Patchset2Id).create();
    // Add comment.
    String commentUuid = newComment(childPatchset1Id).onAutoMergeCommit().onLine(1).ofFile("file1").create();
    CommentInfo portedComment = getPortedComment(childPatchset2Id, commentUuid);
    // Merging the parents creates a conflict in the file. -> Several lines are added due to
    // conflict markers in the auto-merge commit. We don't care about the exact number, just that
    // the comment moved down several lines (instead of just one in each parent) and that the
    // porting logic hence used the auto-merge commit for its computation.
    assertThat(portedComment).line().isGreaterThan(2);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

PatchSet (com.google.gerrit.entities.PatchSet)123 Change (com.google.gerrit.entities.Change)61 Test (org.junit.Test)48 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)41 ObjectId (org.eclipse.jgit.lib.ObjectId)35 RevCommit (org.eclipse.jgit.revwalk.RevCommit)29 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 Project (com.google.gerrit.entities.Project)25 StorageException (com.google.gerrit.exceptions.StorageException)25 Repository (org.eclipse.jgit.lib.Repository)22 IOException (java.io.IOException)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 ChangeData (com.google.gerrit.server.query.change.ChangeData)18 HumanComment (com.google.gerrit.entities.HumanComment)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 Inject (com.google.inject.Inject)14 Map (java.util.Map)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11