use of com.google.gerrit.extensions.common.RevertSubmissionInfo in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionMultipleBranches.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionMultipleBranches() throws Exception {
List<PushOneCommit.Result> resultCommits = new ArrayList<>();
String topic = "topic";
resultCommits.add(createChange(testRepo, "master", "first change", "c.txt", "message", topic));
testRepo.reset("HEAD~1");
createBranch(BranchNameKey.create(project, "other"));
resultCommits.add(createChange(testRepo, "other", "second change", "a.txt", "message", topic));
resultCommits.add(createChange(testRepo, "other", "third change", "b.txt", "Other 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.get(0).current().files().get("c.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("a.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(2).current().files().get("b.txt").linesDeleted).isEqualTo(1);
String sha1FirstChange = resultCommits.get(0).getCommit().getName();
String sha1ThirdChange = resultCommits.get(2).getCommit().getName();
String sha1SecondRevert = revertChanges.get(2).current().commit(false).commit;
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstChange);
assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1ThirdChange);
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondRevert);
assertThat(revertChanges).hasSize(3);
assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(2);
}
use of com.google.gerrit.extensions.common.RevertSubmissionInfo in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionWipMarksAllChangesAsWip.
@Test
public void revertSubmissionWipMarksAllChangesAsWip() throws Exception {
String changeId1 = createChange("first change", "a.txt", "message").getChangeId();
approve(changeId1);
gApi.changes().id(changeId1).addReviewer(user.email());
String changeId2 = createChange("second change", "b.txt", "other").getChangeId();
approve(changeId2);
gApi.changes().id(changeId2).addReviewer(user.email());
gApi.changes().id(changeId2).current().submit();
sender.clear();
RevertInput revertInput = createWipRevertInput();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(changeId2).revertSubmission(revertInput);
assertThat(revertSubmissionInfo.revertChanges.stream().allMatch(r -> r.workInProgress)).isTrue();
}
use of com.google.gerrit.extensions.common.RevertSubmissionInfo in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionDependantAndUnrelatedWithMerge.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionDependantAndUnrelatedWithMerge() throws Exception {
String topic = "topic";
PushOneCommit.Result firstResult = createChange(testRepo, "master", "first change", "a.txt", "message", topic);
approve(firstResult.getChangeId());
PushOneCommit.Result secondResult = createChange(testRepo, "master", "second change", "b.txt", "message", topic);
approve(secondResult.getChangeId());
testRepo.reset("HEAD~1");
PushOneCommit.Result thirdResult = createChange(testRepo, "master", "third change", "c.txt", "message", topic);
approve(thirdResult.getChangeId());
gApi.changes().id(firstResult.getChangeId()).current().submit();
// put the head on the merge commit created by submitting the second and third change.
testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master:merge")).call();
testRepo.reset("merge");
// Create another change that should be ignored. The reverts should be rebased on top of the
// merge commit.
PushOneCommit.Result fourthResult = createChange(testRepo, "master", "fourth change", "d.txt", "message", topic);
approve(fourthResult.getChangeId());
gApi.changes().id(fourthResult.getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(secondResult.getChangeId()).revertSubmission();
assertThat(revertSubmissionInfo.revertChanges.stream().map(change -> change.created).distinct().count()).isEqualTo(1);
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
Collections.reverse(revertChanges);
assertThat(revertChanges.get(0).current().files().get("c.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);
String sha1FirstRevert = revertChanges.get(0).current().commit(false).commit;
String sha1SecondRevert = revertChanges.get(1).current().commit(false).commit;
// parent of the first revert is the merged change of previous changes.
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).subject).contains("Merge");
// Next reverts would stack on top of the previous ones.
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstRevert);
assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondRevert);
assertThat(revertChanges).hasSize(3);
assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(3);
}
use of com.google.gerrit.extensions.common.RevertSubmissionInfo in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionUnrelatedWithAnotherDependantChangeWithDifferentTopic.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionUnrelatedWithAnotherDependantChangeWithDifferentTopic() throws Exception {
String topic = "topic";
PushOneCommit.Result firstResult = createChange(testRepo, "master", "first change", "a.txt", "message", topic);
approve(firstResult.getChangeId());
testRepo.reset("HEAD~1");
PushOneCommit.Result secondResult = createChange(testRepo, "master", "second change", "b.txt", "message", topic);
approve(secondResult.getChangeId());
// A non-merged change without the same topic that is related to the second change.
createChange();
gApi.changes().id(firstResult.getChangeId()).current().submit();
RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(secondResult.getChangeId()).revertSubmission();
List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
Collections.reverse(revertChanges);
assertThat(revertChanges.get(0).current().files().get("b.txt").linesDeleted).isEqualTo(1);
assertThat(revertChanges.get(1).current().files().get("a.txt").linesDeleted).isEqualTo(1);
// The parent of the first revert is the merge change of the submission.
assertThat(revertChanges.get(0).current().commit(false).parents.get(0).subject).contains("Merge \"second change\"");
// Next revert would base itself on the previous revert.
String sha1FirstRevert = revertChanges.get(0).current().commit(false).commit;
assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstRevert);
assertThat(revertChanges).hasSize(2);
}
use of com.google.gerrit.extensions.common.RevertSubmissionInfo in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionNotifications.
@Test
public void revertSubmissionNotifications() throws Exception {
String firstResult = createChange("first change", "a.txt", "message").getChangeId();
approve(firstResult);
gApi.changes().id(firstResult).addReviewer(user.email());
String secondResult = createChange("second change", "b.txt", "other").getChangeId();
approve(secondResult);
gApi.changes().id(secondResult).addReviewer(user.email());
gApi.changes().id(secondResult).current().submit();
sender.clear();
RevertInput revertInput = new RevertInput();
revertInput.notify = NotifyHandling.ALL;
RevertSubmissionInfo revertChanges = gApi.changes().id(secondResult).revertSubmission(revertInput);
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(4);
assertThat(sender.getMessages(revertChanges.revertChanges.get(0).changeId, "newchange")).hasSize(1);
assertThat(sender.getMessages(firstResult, "revert")).hasSize(1);
assertThat(sender.getMessages(revertChanges.revertChanges.get(1).changeId, "newchange")).hasSize(1);
assertThat(sender.getMessages(secondResult, "revert")).hasSize(1);
}
Aggregations