Fail with proper error when trying to revert initial commit

Trying the revert the very first change in a repository, when the
project was created without initial commit, failed with an Internal
Server Error. Instead return '409 Conflict' and inform the user with a
proper error message that this is not supported.

Change-Id: I3638ef9d9383d5cc583e1245c6c9d27e83820839
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2015-10-30 10:26:12 +01:00
parent d98efb657e
commit d218e4078c
2 changed files with 26 additions and 0 deletions

View File

@@ -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;
@@ -226,6 +227,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);