Don't compare commit message against auto-merge commit
When a merge commit is compared against its auto-merge commit, we want to show the complete commit message as new in the diff screen (the same as when the commit is compared against a parent commit). Define a new class ComparisonType that encapsulates the information about whether the comparison is done against a parent or against the auto-merge. If the comparison is done against a parent, include the parent number. The parent number will be needed if we want to have magic files with content that depends on the parent against which the comparison is done. Include the parent number already now, so that we don't need to invalidate the PatchListCache later once more. Commenting on the auto-merge commit message is no longer possible. Old comments that were done on the auto-merge commit message are filtered out when comments are retrieved (because we don't return any content to which they could be applied). Change-Id: I8a75c32a2053f82f8a2f41e0d15747c7f50354c3 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -32,9 +32,11 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
||||
import com.google.gerrit.extensions.client.Comment;
|
||||
import com.google.gerrit.extensions.client.Side;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.ChangesCollection;
|
||||
import com.google.gerrit.server.change.PostReview;
|
||||
@@ -148,8 +150,8 @@ public class CommentsIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void postCommentOnMergeCommitChange() throws Exception {
|
||||
for (Integer line : lines) {
|
||||
final String file = "/COMMIT_MSG";
|
||||
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
|
||||
String file = "foo";
|
||||
PushOneCommit.Result r = createMergeCommitChange("refs/for/master", file);
|
||||
String changeId = r.getChangeId();
|
||||
String revId = r.getCommit().getName();
|
||||
ReviewInput input = new ReviewInput();
|
||||
@@ -165,6 +167,39 @@ public class CommentsIT extends AbstractDaemonTest {
|
||||
assertThat(Lists.transform(result.get(file), infoToInput(file)))
|
||||
.containsExactly(c1, c2, c3, c4);
|
||||
}
|
||||
|
||||
// for the commit message comments on the auto-merge are not possible
|
||||
for (Integer line : lines) {
|
||||
String file = Patch.COMMIT_MSG;
|
||||
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
|
||||
String changeId = r.getChangeId();
|
||||
String revId = r.getCommit().getName();
|
||||
ReviewInput input = new ReviewInput();
|
||||
CommentInput c1 = newComment(file, Side.REVISION, line, "ps-1");
|
||||
CommentInput c2 = newCommentOnParent(file, 1, line, "parent-1 of ps-1");
|
||||
CommentInput c3 = newCommentOnParent(file, 2, line, "parent-2 of ps-1");
|
||||
input.comments = new HashMap<>();
|
||||
input.comments.put(file, ImmutableList.of(c1, c2, c3));
|
||||
revision(r).review(input);
|
||||
Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
|
||||
assertThat(result).isNotEmpty();
|
||||
assertThat(Lists.transform(result.get(file), infoToInput(file)))
|
||||
.containsExactly(c1, c2, c3);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postCommentOnCommitMessageOnAutoMerge() throws Exception {
|
||||
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
|
||||
ReviewInput input = new ReviewInput();
|
||||
CommentInput c =
|
||||
newComment(Patch.COMMIT_MSG, Side.PARENT, 0, "comment on auto-merge");
|
||||
input.comments = new HashMap<>();
|
||||
input.comments.put(Patch.COMMIT_MSG, ImmutableList.of(c));
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage(
|
||||
"cannot comment on " + Patch.COMMIT_MSG + " on auto-merge");
|
||||
revision(r).review(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user