use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionDifferentRepositoriesWithDependantChange.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionDifferentRepositoriesWithDependantChange() throws Exception {
projectOperations.newProject().name("secondProject").create();
TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
List<PushOneCommit.Result> resultCommits = new ArrayList<>();
String topic = "topic";
resultCommits.add(createChange(secondRepo, "master", "first change", "a.txt", "message", topic));
resultCommits.add(createChange(secondRepo, "master", "second change", "b.txt", "Other message", topic));
resultCommits.add(createChange(testRepo, "master", "main repo change", "a.txt", "message", topic));
for (PushOneCommit.Result result : resultCommits) {
approve(result.getChangeId());
}
// submit all changes
gApi.changes().id(resultCommits.get(1).getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(resultCommits.get(1).getChangeId()).revertSubmission();
assertThat(revertSubmissionInfo.revertChanges.stream().map(change -> change.created).distinct().count()).isEqualTo(1);
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
assertThat(revertChanges).hasSize(3);
String sha1RevertOfTheSecondChange = revertChanges.get(1).current().commit(false).commit;
String sha1SecondChange = resultCommits.get(1).getCommit().getName();
String sha1ThirdChange = resultCommits.get(2).getCommit().getName();
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).commit).isEqualTo(sha1RevertOfTheSecondChange);
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondChange);
assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1ThirdChange);
assertThat(revertChanges.get(0).current().files().get("a.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("b.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(2).current().files().get("a.txt").linesDeleted).isEqualTo(1);
// has size 3 because of the same topic, and submitWholeTopic is true.
assertThat(gApi.changes().id(revertChanges.get(0).get()._number).submittedTogether()).hasSize(3);
for (int i = 0; i < resultCommits.size(); i++) {
assertThat(revertChanges.get(i).get().revertOf).isEqualTo(resultCommits.get(i).getChange().change().getChangeId());
List<ChangeMessageInfo> sourceMessages = new ArrayList<>(gApi.changes().id(resultCommits.get(i).getChangeId()).get().messages);
assertThat(sourceMessages).hasSize(4);
String expectedMessage = String.format("Created a revert of this change as %s", revertChanges.get(i).get().changeId);
assertThat(sourceMessages.get(3).message).isEqualTo(expectedMessage);
// Expected message on the created change: "Uploaded patch set 1."
List<ChangeMessageInfo> messages = revertChanges.get(i).get().messages.stream().collect(toList());
assertThat(messages).hasSize(1);
assertThat(messages.get(0).message).isEqualTo("Uploaded patch set 1.");
assertThat(revertChanges.get(i).get().revertOf).isEqualTo(gApi.changes().id(resultCommits.get(i).getChangeId()).get()._number);
assertThat(revertChanges.get(i).get().topic).startsWith("revert-" + resultCommits.get(0).getChange().change().getSubmissionId());
}
assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(2);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickConflictWithAllowConflicts.
@Test
public void cherryPickConflictWithAllowConflicts() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
// Create a branch and push a commit to it (by-passing review)
String destBranch = "foo";
gApi.projects().name(project.get()).branch(destBranch).create(new BranchInput());
String destContent = "some content";
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, PushOneCommit.SUBJECT, ImmutableMap.of(PushOneCommit.FILE_NAME, destContent, "foo.txt", "foo"));
push.to("refs/heads/" + destBranch);
// Create a change on master with a commit that conflicts with the commit on the other branch.
testRepo.reset(initial);
String changeContent = "another content";
push = pushFactory.create(admin.newIdent(), testRepo, PushOneCommit.SUBJECT, ImmutableMap.of(PushOneCommit.FILE_NAME, changeContent, "bar.txt", "bar"));
PushOneCommit.Result r = push.to("refs/for/master%topic=someTopic");
// Verify before the cherry-pick that the change has exactly 1 message.
ChangeApi changeApi = change(r);
assertThat(changeApi.get().messages).hasSize(1);
// Cherry-pick the change to the other branch, that should fail with a conflict.
CherryPickInput in = new CherryPickInput();
in.destination = destBranch;
in.message = "Cherry-Pick";
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> changeApi.revision(r.getCommit().name()).cherryPickAsInfo(in));
assertThat(thrown).hasMessageThat().startsWith("Cherry pick failed: merge conflict");
// Cherry-pick with auto merge should succeed.
in.allowConflicts = true;
ChangeInfo cherryPickChange = changeApi.revision(r.getCommit().name()).cherryPickAsInfo(in);
assertThat(cherryPickChange.containsGitConflicts).isTrue();
assertThat(cherryPickChange.workInProgress).isTrue();
// Verify that subject and topic on the cherry-pick change have been correctly populated.
assertThat(cherryPickChange.subject).contains(in.message);
assertThat(cherryPickChange.topic).isEqualTo("someTopic-" + destBranch);
// Verify that the file content in the cherry-pick change is correct.
// We expect that it has conflict markers to indicate the conflict.
BinaryResult bin = gApi.changes().id(cherryPickChange._number).current().file(PushOneCommit.FILE_NAME).content();
ByteArrayOutputStream os = new ByteArrayOutputStream();
bin.writeTo(os);
String fileContent = new String(os.toByteArray(), UTF_8);
String destSha1 = abbreviateName(projectOperations.project(project).getHead(destBranch), 6);
String changeSha1 = abbreviateName(r.getCommit(), 6);
assertThat(fileContent).isEqualTo("<<<<<<< HEAD (" + destSha1 + " test commit)\n" + destContent + "\n" + "=======\n" + changeContent + "\n" + ">>>>>>> CHANGE (" + changeSha1 + " test commit)\n");
// Get details of cherry-pick change.
ChangeInfo cherryPickChangeWithDetails = gApi.changes().id(cherryPickChange._number).get();
assertThat(cherryPickChangeWithDetails.workInProgress).isTrue();
// Verify that a message has been posted on the cherry-pick change.
assertThat(cherryPickChangeWithDetails.messages).hasSize(1);
Iterator<ChangeMessageInfo> cherryIt = cherryPickChangeWithDetails.messages.iterator();
assertThat(cherryIt.next().message).isEqualTo("Patch Set 1: Cherry Picked from branch master.\n\n" + "The following files contain Git conflicts:\n" + "* " + PushOneCommit.FILE_NAME);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPick.
@Test
public void cherryPick() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master%topic=someTopic");
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = "it goes to stable branch";
gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
assertThat(orig.get().messages).hasSize(1);
ChangeInfo changeInfo = orig.revision(r.getCommit().name()).cherryPickAsInfo(in);
assertThat(changeInfo.containsGitConflicts).isNull();
assertThat(changeInfo.workInProgress).isNull();
ChangeApi cherry = gApi.changes().id(changeInfo._number);
ChangeInfo cherryPickChangeInfoWithDetails = cherry.get();
assertThat(cherryPickChangeInfoWithDetails.workInProgress).isNull();
assertThat(cherryPickChangeInfoWithDetails.messages).hasSize(1);
Iterator<ChangeMessageInfo> cherryIt = cherryPickChangeInfoWithDetails.messages.iterator();
assertThat(cherryIt.next().message).isEqualTo("Patch Set 1: Cherry Picked from branch master.");
assertThat(cherry.get().subject).contains(in.message);
assertThat(cherry.get().topic).isEqualTo("someTopic-foo");
assertThat(cherry.get().cherryPickOfChange).isEqualTo(orig.get()._number);
assertThat(cherry.get().cherryPickOfPatchSet).isEqualTo(1);
cherry.current().review(ReviewInput.approve());
cherry.current().submit();
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithPercentEncodedMessage.
@Test
public void pushForMasterWithPercentEncodedMessage() throws Exception {
// Exercise percent-encoding of UTF-8, underscores, and patterns reserved by git-rev-parse.
PushOneCommit.Result r = pushTo("refs/for/master%m=" + "Punctu%2E%2e%2Eation%7E%2D%40%7Bu%7D%20%7C%20%28%E2%95%AF%C2%B0%E2%96%A1%C2%B0" + "%EF%BC%89%E2%95%AF%EF%B8%B5%20%E2%94%BB%E2%94%81%E2%94%BB%20%5E%5F%5E");
r.assertOkStatus();
r.assertChange(Change.Status.NEW, null);
ChangeInfo ci = get(r.getChangeId(), MESSAGES, ALL_REVISIONS);
Collection<ChangeMessageInfo> changeMessages = ci.messages;
assertThat(changeMessages).hasSize(1);
for (ChangeMessageInfo cm : changeMessages) {
assertThat(cm.message).isEqualTo("Uploaded patch set 1.\nPunctu...ation~-@{u} | (╯°□°)╯︵ ┻━┻ ^_^");
}
Collection<RevisionInfo> revisions = ci.revisions.values();
assertThat(revisions).hasSize(1);
for (RevisionInfo ri : revisions) {
assertThat(ri.description).isEqualTo("Punctu...ation~-@{u} | (╯°□°)╯︵ ┻━┻ ^_^");
}
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithMessage.
@Test
public void pushForMasterWithMessage() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master%m=my_test_message");
r.assertOkStatus();
r.assertChange(Change.Status.NEW, null);
ChangeInfo ci = get(r.getChangeId(), MESSAGES, ALL_REVISIONS);
Collection<ChangeMessageInfo> changeMessages = ci.messages;
assertThat(changeMessages).hasSize(1);
for (ChangeMessageInfo cm : changeMessages) {
assertThat(cm.message).isEqualTo("Uploaded patch set 1.\nmy test message");
}
Collection<RevisionInfo> revisions = ci.revisions.values();
assertThat(revisions).hasSize(1);
for (RevisionInfo ri : revisions) {
assertThat(ri.description).isEqualTo("my test message");
}
}
Aggregations