Merge "Revision API: Add method to query if revision must be rebased"
This commit is contained in:
commit
1724b8d2cc
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.acceptance.api.revision;
|
package com.google.gerrit.acceptance.api.revision;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
@ -21,6 +24,7 @@ import com.google.gerrit.acceptance.TestAccount;
|
|||||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||||
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.SubmitInput;
|
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
@ -140,6 +144,42 @@ public class RevisionIT extends AbstractDaemonTest {
|
|||||||
.submit();
|
.submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canRebase()
|
||||||
|
throws GitAPIException, IOException, RestApiException, Exception {
|
||||||
|
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||||
|
PushOneCommit.Result r1 = push.to(git, "refs/for/master");
|
||||||
|
merge(r1);
|
||||||
|
|
||||||
|
push = pushFactory.create(db, admin.getIdent());
|
||||||
|
PushOneCommit.Result r2 = push.to(git, "refs/for/master");
|
||||||
|
assertFalse(gApi.changes()
|
||||||
|
.id(r2.getChangeId())
|
||||||
|
.revision(r2.getCommit().name())
|
||||||
|
.canRebase());
|
||||||
|
merge(r2);
|
||||||
|
|
||||||
|
git.checkout().setName(r1.getCommit().name()).call();
|
||||||
|
push = pushFactory.create(db, admin.getIdent());
|
||||||
|
PushOneCommit.Result r3 = push.to(git, "refs/for/master");
|
||||||
|
|
||||||
|
assertTrue(gApi.changes()
|
||||||
|
.id(r3.getChangeId())
|
||||||
|
.revision(r3.getCommit().name())
|
||||||
|
.canRebase());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RevisionApi revision(PushOneCommit.Result r) throws Exception {
|
||||||
|
return gApi.changes()
|
||||||
|
.id(r.getChangeId())
|
||||||
|
.current();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void merge(PushOneCommit.Result r) throws Exception {
|
||||||
|
revision(r).review(ReviewInput.approve());
|
||||||
|
revision(r).submit();
|
||||||
|
}
|
||||||
|
|
||||||
private PushOneCommit.Result updateChange(PushOneCommit.Result r,
|
private PushOneCommit.Result updateChange(PushOneCommit.Result r,
|
||||||
String content) throws GitAPIException, IOException {
|
String content) throws GitAPIException, IOException {
|
||||||
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
|
PushOneCommit push = pushFactory.create(db, admin.getIdent(),
|
||||||
|
@ -26,4 +26,5 @@ public interface RevisionApi {
|
|||||||
void publish() throws RestApiException;
|
void publish() throws RestApiException;
|
||||||
ChangeApi cherryPick(CherryPickInput in) throws RestApiException;
|
ChangeApi cherryPick(CherryPickInput in) throws RestApiException;
|
||||||
ChangeApi rebase() throws RestApiException;
|
ChangeApi rebase() throws RestApiException;
|
||||||
|
boolean canRebase();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import com.google.gerrit.server.change.Publish;
|
|||||||
import com.google.gerrit.server.change.Rebase;
|
import com.google.gerrit.server.change.Rebase;
|
||||||
import com.google.gerrit.server.change.RevisionResource;
|
import com.google.gerrit.server.change.RevisionResource;
|
||||||
import com.google.gerrit.server.change.Submit;
|
import com.google.gerrit.server.change.Submit;
|
||||||
|
import com.google.gerrit.server.changedetail.RebaseChange;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
@ -45,6 +46,7 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
private final Provider<CherryPick> cherryPick;
|
private final Provider<CherryPick> cherryPick;
|
||||||
private final Provider<DeleteDraftPatchSet> deleteDraft;
|
private final Provider<DeleteDraftPatchSet> deleteDraft;
|
||||||
private final Provider<Rebase> rebase;
|
private final Provider<Rebase> rebase;
|
||||||
|
private final Provider<RebaseChange> rebaseChange;
|
||||||
private final Provider<PostReview> review;
|
private final Provider<PostReview> review;
|
||||||
private final Provider<Submit> submit;
|
private final Provider<Submit> submit;
|
||||||
private final Provider<Publish> publish;
|
private final Provider<Publish> publish;
|
||||||
@ -55,6 +57,7 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
Provider<CherryPick> cherryPick,
|
Provider<CherryPick> cherryPick,
|
||||||
Provider<DeleteDraftPatchSet> deleteDraft,
|
Provider<DeleteDraftPatchSet> deleteDraft,
|
||||||
Provider<Rebase> rebase,
|
Provider<Rebase> rebase,
|
||||||
|
Provider<RebaseChange> rebaseChange,
|
||||||
Provider<PostReview> review,
|
Provider<PostReview> review,
|
||||||
Provider<Submit> submit,
|
Provider<Submit> submit,
|
||||||
Provider<Publish> publish,
|
Provider<Publish> publish,
|
||||||
@ -63,6 +66,7 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
this.cherryPick = cherryPick;
|
this.cherryPick = cherryPick;
|
||||||
this.deleteDraft = deleteDraft;
|
this.deleteDraft = deleteDraft;
|
||||||
this.rebase = rebase;
|
this.rebase = rebase;
|
||||||
|
this.rebaseChange = rebaseChange;
|
||||||
this.review = review;
|
this.review = review;
|
||||||
this.submit = submit;
|
this.submit = submit;
|
||||||
this.publish = publish;
|
this.publish = publish;
|
||||||
@ -121,6 +125,11 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRebase() {
|
||||||
|
return rebaseChange.get().canRebase(revision);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
|
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user