use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class CreateMergePatchSetIT method createMergePatchSet_ConflictAllowed.
@Test
public void createMergePatchSet_ConflictAllowed() throws Exception {
RevCommit initialHead = projectOperations.project(project).getHead("master");
createBranch(BranchNameKey.create(project, "dev"));
// create a change for master
String changeId = createChange().getChangeId();
String fileName = "shared.txt";
String sourceSubject = "source change";
String sourceContent = "source content";
String targetSubject = "target change";
String targetContent = "target content";
testRepo.reset(initialHead);
PushOneCommit.Result currentMaster = pushFactory.create(admin.newIdent(), testRepo, targetSubject, fileName, targetContent).to("refs/heads/master");
currentMaster.assertOkStatus();
String parent = currentMaster.getCommit().getName();
// push a commit into dev branch
testRepo.reset(initialHead);
PushOneCommit.Result changeA = pushFactory.create(user.newIdent(), testRepo, sourceSubject, fileName, sourceContent).to("refs/heads/dev");
changeA.assertOkStatus();
MergeInput mergeInput = new MergeInput();
mergeInput.source = "dev";
mergeInput.allowConflicts = true;
MergePatchSetInput in = new MergePatchSetInput();
in.merge = mergeInput;
in.subject = "update change by merge ps2";
TestWorkInProgressStateChangedListener wipStateChangedListener = new TestWorkInProgressStateChangedListener();
try (ExtensionRegistry.Registration registration = extensionRegistry.newRegistration().add(wipStateChangedListener)) {
ChangeInfo changeInfo = gApi.changes().id(changeId).createMergePatchSet(in);
assertThat(changeInfo.subject).isEqualTo(in.subject);
assertThat(changeInfo.containsGitConflicts).isTrue();
assertThat(changeInfo.workInProgress).isTrue();
}
assertThat(wipStateChangedListener.invoked).isTrue();
assertThat(wipStateChangedListener.wip).isTrue();
// To get the revisions, we must retrieve the change with more change options.
ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(changeInfo.revisions).hasSize(2);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(parent);
// Verify that the file content in the created patch set is correct.
// We expect that it has conflict markers to indicate the conflict.
BinaryResult bin = gApi.changes().id(changeId).current().file(fileName).content();
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String fileContent = new String(os.toByteArray(), UTF_8);
String sourceSha1 = abbreviateName(changeA.getCommit(), 6);
String targetSha1 = abbreviateName(currentMaster.getCommit(), 6);
assertThat(fileContent).isEqualTo("<<<<<<< TARGET BRANCH (" + targetSha1 + " " + targetSubject + ")\n" + targetContent + "\n" + "=======\n" + sourceContent + "\n" + ">>>>>>> SOURCE BRANCH (" + sourceSha1 + " " + sourceSubject + ")\n");
// Verify the message that has been posted on the change.
List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
assertThat(messages).hasSize(2);
assertThat(Iterables.getLast(messages).message).isEqualTo("Uploaded patch set 2.\n\n" + "The following files contain Git conflicts:\n" + "* " + fileName + "\n");
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ChangeIT method rebaseConflict_conflictsAllowed.
@Test
public void rebaseConflict_conflictsAllowed() throws Exception {
String patchSetSubject = "patch set change";
String patchSetContent = "patch set content";
String baseSubject = "base change";
String baseContent = "base content";
PushOneCommit.Result r1 = createChange(baseSubject, PushOneCommit.FILE_NAME, baseContent);
gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).review(ReviewInput.approve());
gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).submit();
testRepo.reset("HEAD~1");
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, patchSetSubject, PushOneCommit.FILE_NAME, patchSetContent);
PushOneCommit.Result r2 = push.to("refs/for/master");
r2.assertOkStatus();
String changeId = r2.getChangeId();
RevCommit patchSet = r2.getCommit();
RevCommit base = r1.getCommit();
TestWorkInProgressStateChangedListener wipStateChangedListener = new TestWorkInProgressStateChangedListener();
try (Registration registration = extensionRegistry.newRegistration().add(wipStateChangedListener)) {
RebaseInput rebaseInput = new RebaseInput();
rebaseInput.allowConflicts = true;
ChangeInfo changeInfo = gApi.changes().id(changeId).revision(patchSet.name()).rebaseAsInfo(rebaseInput);
assertThat(changeInfo.containsGitConflicts).isTrue();
assertThat(changeInfo.workInProgress).isTrue();
}
assertThat(wipStateChangedListener.invoked).isTrue();
assertThat(wipStateChangedListener.wip).isTrue();
// To get the revisions, we must retrieve the change with more change options.
ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(changeInfo.revisions).hasSize(2);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(base.name());
// Verify that the file content in the created patch set is correct.
// We expect that it has conflict markers to indicate the conflict.
BinaryResult bin = gApi.changes().id(changeId).current().file(PushOneCommit.FILE_NAME).content();
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String fileContent = new String(os.toByteArray(), UTF_8);
String patchSetSha1 = abbreviateName(patchSet, 6);
String baseSha1 = abbreviateName(base, 6);
assertThat(fileContent).isEqualTo("<<<<<<< PATCH SET (" + patchSetSha1 + " " + patchSetSubject + ")\n" + patchSetContent + "\n" + "=======\n" + baseContent + "\n" + ">>>>>>> BASE (" + baseSha1 + " " + baseSubject + ")\n");
// Verify the message that has been posted on the change.
List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
assertThat(messages).hasSize(2);
assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 2: Patch Set 1 was rebased\n\n" + "The following files contain Git conflicts:\n" + "* " + PushOneCommit.FILE_NAME + "\n");
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ListMailFilterIT method listFilterAllowFiltersNotListedUser.
@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+@gerritcodereview\\.com", "a@b\\.com" })
public void listFilterAllowFiltersNotListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have NOT been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
assertThat(messages).hasSize(2);
// Check that no emails were sent because of this error
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ListMailFilterIT method listFilterBlockDoesNotFilterNotListedUser.
@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "BLOCK")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+@gerritcodereview\\.com", "a@b\\.com" })
public void listFilterBlockDoesNotFilterNotListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
assertThat(messages).hasSize(3);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ListMailFilterIT method listFilterAllowDoesNotFilterListedUser.
@Test
@GerritConfig(name = "receiveemail.filter.mode", value = "ALLOW")
@GerritConfig(name = "receiveemail.filter.patterns", values = { ".+ser1@example\\.com", "a@b\\.com" })
public void listFilterAllowDoesNotFilterListedUser() throws Exception {
ChangeInfo changeInfo = createChangeAndReplyByEmail();
// Check that the comments from the email have been persisted
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeInfo.id).get().messages;
assertThat(messages).hasSize(3);
}
Aggregations