Search in sources :

Example 1 with RevertSubmissionInfo

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);
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ArrayList(java.util.ArrayList) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with RevertSubmissionInfo

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();
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with RevertSubmissionInfo

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);
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RefSpec(org.eclipse.jgit.transport.RefSpec) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with RevertSubmissionInfo

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);
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with RevertSubmissionInfo

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);
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

RevertSubmissionInfo (com.google.gerrit.extensions.common.RevertSubmissionInfo)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 Test (org.junit.Test)9 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)7 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 RevertInput (com.google.gerrit.extensions.api.changes.RevertInput)3 ArrayList (java.util.ArrayList)3 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 FluentLogger (com.google.common.flogger.FluentLogger)1 BranchNameKey (com.google.gerrit.entities.BranchNameKey)1 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 RefNames (com.google.gerrit.entities.RefNames)1 StorageException (com.google.gerrit.exceptions.StorageException)1