Do not fail with 500 ISE if base of merge change cannot be computed due to NoMergeBaseException

If the repository content doesn't allow us to compute an auto-merge
commit for the base of a merge change because JGit cannot find a merge
base (e.g. due to CONFLICTS_DURING_MERGE_BASE_CALCULATION), we now
return '409 Conflict' for the ListFiles and change-edit-related REST
endpoints. If the files were supposed to be included into a ChangeInfo /
RevisionInfo we ignore the failure and just do not populate the file
list (but we log a warning). Letting the request succeed in this case is
better, as the caller can at least get the rest of the change and
revision information.

Treating NoMergeBaseException as '409 Conflict' is consistent with how
we treat this exception in other places (e.g. in the CreateChange REST
endpoint).

Change-Id: I78b4636c23635048eedf2a1e4b1075eb87ecb262
This commit is contained in:
Edwin Kempin
2020-01-15 12:11:20 +01:00
parent 417233022d
commit 1f834ad6f0
4 changed files with 34 additions and 11 deletions

View File

@@ -184,7 +184,8 @@ public class ChangeEdits implements ChildCollection<ChangeResource, ChangeEditRe
@Override
public Response<EditInfo> apply(ChangeResource rsrc)
throws AuthException, IOException, ResourceNotFoundException, PermissionBackendException {
throws AuthException, IOException, ResourceNotFoundException, ResourceConflictException,
PermissionBackendException {
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getNotes(), rsrc.getUser());
if (!edit.isPresent()) {
return Response.none();

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.extensions.common.FileInfo;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.ChildCollection;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestReadView;
@@ -86,7 +87,7 @@ public class FilesInCommitCollection implements ChildCollection<CommitResource,
@Override
public Response<Map<String, FileInfo>> apply(CommitResource resource)
throws PatchListNotAvailableException {
throws ResourceConflictException, PatchListNotAvailableException {
RevCommit commit = resource.getCommit();
PatchListKey key;