ChangeIT: Check related changes of rebased change
Change-Id: Id4e03c29203b275006abe0dcc8fb06cbcf748386
This commit is contained in:
@@ -50,6 +50,7 @@ import com.google.gerrit.common.data.Permission;
|
|||||||
import com.google.gerrit.common.data.PermissionRule;
|
import com.google.gerrit.common.data.PermissionRule;
|
||||||
import com.google.gerrit.common.data.PermissionRule.Action;
|
import com.google.gerrit.common.data.PermissionRule.Action;
|
||||||
import com.google.gerrit.extensions.api.GerritApi;
|
import com.google.gerrit.extensions.api.GerritApi;
|
||||||
|
import com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||||
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
|
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
|
||||||
@@ -1714,4 +1715,13 @@ public abstract class AbstractDaemonTest {
|
|||||||
comments.sort(Comparator.comparing(c -> c.id));
|
comments.sort(Comparator.comparing(c -> c.id));
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected List<RelatedChangeAndCommitInfo> getRelated(PatchSet.Id ps) throws Exception {
|
||||||
|
return getRelated(ps.getParentKey(), ps.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<RelatedChangeAndCommitInfo> getRelated(Change.Id changeId, int ps)
|
||||||
|
throws Exception {
|
||||||
|
return gApi.changes().id(changeId.get()).revision(ps).related().changes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
|||||||
import com.google.gerrit.extensions.api.changes.NotifyInfo;
|
import com.google.gerrit.extensions.api.changes.NotifyInfo;
|
||||||
import com.google.gerrit.extensions.api.changes.RebaseInput;
|
import com.google.gerrit.extensions.api.changes.RebaseInput;
|
||||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
import com.google.gerrit.extensions.api.changes.RecipientType;
|
||||||
|
import com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo;
|
||||||
import com.google.gerrit.extensions.api.changes.RevertInput;
|
import com.google.gerrit.extensions.api.changes.RevertInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
|
||||||
@@ -943,13 +944,87 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
RevisionInfo ri2 = ci2.revisions.get(ci2.currentRevision);
|
RevisionInfo ri2 = ci2.revisions.get(ci2.currentRevision);
|
||||||
assertThat(ri2.commit.parents.get(0).commit).isEqualTo(branchTip);
|
assertThat(ri2.commit.parents.get(0).commit).isEqualTo(branchTip);
|
||||||
|
|
||||||
|
Change.Id id1 = r1.getChange().getId();
|
||||||
RebaseInput in = new RebaseInput();
|
RebaseInput in = new RebaseInput();
|
||||||
in.base = Integer.toString(r1.getChange().getId().get());
|
in.base = id1.toString();
|
||||||
gApi.changes().id(r2.getChangeId()).rebase(in);
|
gApi.changes().id(r2.getChangeId()).rebase(in);
|
||||||
|
|
||||||
|
Change.Id id2 = r2.getChange().getId();
|
||||||
ci2 = get(r2.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
|
ci2 = get(r2.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
|
||||||
ri2 = ci2.revisions.get(ci2.currentRevision);
|
ri2 = ci2.revisions.get(ci2.currentRevision);
|
||||||
assertThat(ri2.commit.parents.get(0).commit).isEqualTo(r1.getCommit().name());
|
assertThat(ri2.commit.parents.get(0).commit).isEqualTo(r1.getCommit().name());
|
||||||
|
|
||||||
|
List<RelatedChangeAndCommitInfo> related = getRelated(id2, ri2._number);
|
||||||
|
assertThat(related).hasSize(2);
|
||||||
|
assertThat(related.get(0)._changeNumber).isEqualTo(id2.get());
|
||||||
|
assertThat(related.get(0)._revisionNumber).isEqualTo(2);
|
||||||
|
assertThat(related.get(1)._changeNumber).isEqualTo(id1.get());
|
||||||
|
assertThat(related.get(1)._revisionNumber).isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rebaseOnClosedChange() throws Exception {
|
||||||
|
String branchTip = testRepo.getRepository().exactRef("HEAD").getObjectId().name();
|
||||||
|
PushOneCommit.Result r1 = createChange();
|
||||||
|
testRepo.reset("HEAD~1");
|
||||||
|
PushOneCommit.Result r2 = createChange();
|
||||||
|
|
||||||
|
ChangeInfo ci2 = get(r2.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
|
||||||
|
RevisionInfo ri2 = ci2.revisions.get(ci2.currentRevision);
|
||||||
|
assertThat(ri2.commit.parents.get(0).commit).isEqualTo(branchTip);
|
||||||
|
|
||||||
|
// Submit first change.
|
||||||
|
Change.Id id1 = r1.getChange().getId();
|
||||||
|
gApi.changes().id(id1.get()).current().review(ReviewInput.approve());
|
||||||
|
gApi.changes().id(id1.get()).current().submit();
|
||||||
|
|
||||||
|
// Rebase second change on first change.
|
||||||
|
RebaseInput in = new RebaseInput();
|
||||||
|
in.base = id1.toString();
|
||||||
|
gApi.changes().id(r2.getChangeId()).rebase(in);
|
||||||
|
|
||||||
|
Change.Id id2 = r2.getChange().getId();
|
||||||
|
ci2 = get(r2.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
|
||||||
|
ri2 = ci2.revisions.get(ci2.currentRevision);
|
||||||
|
assertThat(ri2.commit.parents.get(0).commit).isEqualTo(r1.getCommit().name());
|
||||||
|
|
||||||
|
List<RelatedChangeAndCommitInfo> related = getRelated(id2, ri2._number);
|
||||||
|
assertThat(related).hasSize(2);
|
||||||
|
assertThat(related.get(0)._changeNumber).isEqualTo(id2.get());
|
||||||
|
assertThat(related.get(0)._revisionNumber).isEqualTo(2);
|
||||||
|
assertThat(related.get(1)._changeNumber).isEqualTo(id1.get());
|
||||||
|
assertThat(related.get(1)._revisionNumber).isEqualTo(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rebaseFromRelationChainToClosedChange() throws Exception {
|
||||||
|
PushOneCommit.Result r1 = createChange();
|
||||||
|
testRepo.reset("HEAD~1");
|
||||||
|
|
||||||
|
createChange();
|
||||||
|
PushOneCommit.Result r3 = createChange();
|
||||||
|
|
||||||
|
// Submit first change.
|
||||||
|
Change.Id id1 = r1.getChange().getId();
|
||||||
|
gApi.changes().id(id1.get()).current().review(ReviewInput.approve());
|
||||||
|
gApi.changes().id(id1.get()).current().submit();
|
||||||
|
|
||||||
|
// Rebase third change on first change.
|
||||||
|
RebaseInput in = new RebaseInput();
|
||||||
|
in.base = id1.toString();
|
||||||
|
gApi.changes().id(r3.getChangeId()).rebase(in);
|
||||||
|
|
||||||
|
Change.Id id3 = r3.getChange().getId();
|
||||||
|
ChangeInfo ci3 = get(r3.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT);
|
||||||
|
RevisionInfo ri3 = ci3.revisions.get(ci3.currentRevision);
|
||||||
|
assertThat(ri3.commit.parents.get(0).commit).isEqualTo(r1.getCommit().name());
|
||||||
|
|
||||||
|
List<RelatedChangeAndCommitInfo> related = getRelated(id3, ri3._number);
|
||||||
|
assertThat(related).hasSize(2);
|
||||||
|
assertThat(related.get(0)._changeNumber).isEqualTo(id3.get());
|
||||||
|
assertThat(related.get(0)._revisionNumber).isEqualTo(2);
|
||||||
|
assertThat(related.get(1)._changeNumber).isEqualTo(id1.get());
|
||||||
|
assertThat(related.get(1)._revisionNumber).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -577,14 +577,6 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
|||||||
assertRelated(cd.change().currentPatchSetId());
|
assertRelated(cd.change().currentPatchSetId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<RelatedChangeAndCommitInfo> getRelated(PatchSet.Id ps) throws Exception {
|
|
||||||
return getRelated(ps.getParentKey(), ps.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<RelatedChangeAndCommitInfo> getRelated(Change.Id changeId, int ps) throws Exception {
|
|
||||||
return gApi.changes().id(changeId.get()).revision(ps).related().changes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RevCommit parseBody(RevCommit c) throws Exception {
|
private RevCommit parseBody(RevCommit c) throws Exception {
|
||||||
testRepo.getRevWalk().parseBody(c);
|
testRepo.getRevWalk().parseBody(c);
|
||||||
return c;
|
return c;
|
||||||
|
|||||||
Reference in New Issue
Block a user