Merge "Handle commit validation errors when publishing change edit"

This commit is contained in:
Edwin Kempin
2015-06-23 09:16:36 +00:00
committed by Gerrit Code Review
3 changed files with 13 additions and 12 deletions

View File

@@ -28,7 +28,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.edit.ChangeEdit;
import com.google.gerrit.server.edit.ChangeEditUtil;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
@@ -84,7 +83,7 @@ public class PublishChangeEdit implements
@Override
public Response<?> apply(ChangeResource rsrc, Publish.Input in)
throws AuthException, ResourceConflictException, NoSuchChangeException,
IOException, InvalidChangeOperationException, OrmException {
IOException, OrmException {
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
if (!edit.isPresent()) {
throw new ResourceConflictException(String.format(

View File

@@ -143,13 +143,11 @@ public class ChangeEditUtil {
* @param edit change edit to publish
* @throws NoSuchChangeException
* @throws IOException
* @throws InvalidChangeOperationException
* @throws OrmException
* @throws ResourceConflictException
*/
public void publish(ChangeEdit edit) throws NoSuchChangeException,
IOException, InvalidChangeOperationException,
OrmException, ResourceConflictException {
IOException, OrmException, ResourceConflictException {
Change change = edit.getChange();
try (Repository repo = gitManager.openRepository(change.getProject());
RevWalk rw = new RevWalk(repo);
@@ -160,12 +158,16 @@ public class ChangeEditUtil {
"only edit for current patch set can be published");
}
Change updatedChange =
insertPatchSet(edit, change, repo, rw, basePatchSet,
squashEdit(rw, inserter, edit.getEditCommit(), basePatchSet));
// TODO(davido): This should happen in the same BatchRefUpdate.
deleteRef(repo, edit);
indexer.index(db.get(), updatedChange);
try {
Change updatedChange =
insertPatchSet(edit, change, repo, rw, basePatchSet,
squashEdit(rw, inserter, edit.getEditCommit(), basePatchSet));
// TODO(davido): This should happen in the same BatchRefUpdate.
deleteRef(repo, edit);
indexer.index(db.get(), updatedChange);
} catch (InvalidChangeOperationException e) {
throw new ResourceConflictException(e.getMessage());
}
}
}