Merge "Fail with proper error when trying to revert initial commit"
This commit is contained in:
@@ -29,6 +29,7 @@ import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.TestProjectInput;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||
@@ -150,6 +151,26 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
.isEqualTo("Uploaded patch set 1.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestProjectInput(createEmptyCommit = false)
|
||||
public void revertInitialCommit() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.revision(r.getCommit().name())
|
||||
.review(ReviewInput.approve());
|
||||
gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.revision(r.getCommit().name())
|
||||
.submit();
|
||||
|
||||
exception.expect(ResourceConflictException.class);
|
||||
exception.expectMessage("Cannot revert initial commit");
|
||||
gApi.changes()
|
||||
.id(r.getChangeId())
|
||||
.revert();
|
||||
}
|
||||
|
||||
// Change is already up to date
|
||||
@Test(expected = ResourceConflictException.class)
|
||||
public void rebase() throws Exception {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -234,6 +235,10 @@ public class ChangeUtil {
|
||||
PersonIdent authorIdent = user.get()
|
||||
.newCommitterIdent(myIdent.getWhen(), myIdent.getTimeZone());
|
||||
|
||||
if (commitToRevert.getParentCount() == 0) {
|
||||
throw new ResourceConflictException("Cannot revert initial commit");
|
||||
}
|
||||
|
||||
RevCommit parentToCommitToRevert = commitToRevert.getParent(0);
|
||||
revWalk.parseHeaders(parentToCommitToRevert);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user