Merge "Revision API: Add method to query if revision must be rebased"

This commit is contained in:
Shawn Pearce 2014-03-24 23:58:50 +00:00 committed by Gerrit Code Review
commit 1724b8d2cc
3 changed files with 50 additions and 0 deletions

View File

@ -14,6 +14,9 @@
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.NoHttpd;
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.CherryPickInput;
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.projects.BranchInput;
import com.google.gerrit.extensions.restapi.AuthException;
@ -140,6 +144,42 @@ public class RevisionIT extends AbstractDaemonTest {
.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,
String content) throws GitAPIException, IOException {
PushOneCommit push = pushFactory.create(db, admin.getIdent(),

View File

@ -26,4 +26,5 @@ public interface RevisionApi {
void publish() throws RestApiException;
ChangeApi cherryPick(CherryPickInput in) throws RestApiException;
ChangeApi rebase() throws RestApiException;
boolean canRebase();
}

View File

@ -29,6 +29,7 @@ import com.google.gerrit.server.change.Publish;
import com.google.gerrit.server.change.Rebase;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.change.Submit;
import com.google.gerrit.server.changedetail.RebaseChange;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@ -45,6 +46,7 @@ class RevisionApiImpl implements RevisionApi {
private final Provider<CherryPick> cherryPick;
private final Provider<DeleteDraftPatchSet> deleteDraft;
private final Provider<Rebase> rebase;
private final Provider<RebaseChange> rebaseChange;
private final Provider<PostReview> review;
private final Provider<Submit> submit;
private final Provider<Publish> publish;
@ -55,6 +57,7 @@ class RevisionApiImpl implements RevisionApi {
Provider<CherryPick> cherryPick,
Provider<DeleteDraftPatchSet> deleteDraft,
Provider<Rebase> rebase,
Provider<RebaseChange> rebaseChange,
Provider<PostReview> review,
Provider<Submit> submit,
Provider<Publish> publish,
@ -63,6 +66,7 @@ class RevisionApiImpl implements RevisionApi {
this.cherryPick = cherryPick;
this.deleteDraft = deleteDraft;
this.rebase = rebase;
this.rebaseChange = rebaseChange;
this.review = review;
this.submit = submit;
this.publish = publish;
@ -121,6 +125,11 @@ class RevisionApiImpl implements RevisionApi {
}
}
@Override
public boolean canRebase() {
return rebaseChange.get().canRebase(revision);
}
@Override
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
try {