DeleteTag: remove unreachable check

Change-Id: Ia4bcbc1306898c771b8634c9a7c1d37bbbd82be4
This commit is contained in:
Han-Wen Nienhuys
2021-01-11 19:44:49 +01:00
parent 9a65cf9ab0
commit acb8e90347
2 changed files with 4 additions and 7 deletions

View File

@@ -102,6 +102,7 @@ public class RefUtil {
return Constants.R_HEADS; return Constants.R_HEADS;
} }
/** Fully qualifies a tag name to refs/tags/TAG-NAME */
public static String normalizeTagRef(String tag) throws BadRequestException { public static String normalizeTagRef(String tag) throws BadRequestException {
String result = tag; String result = tag;
while (result.startsWith("/")) { while (result.startsWith("/")) {

View File

@@ -14,10 +14,8 @@
package com.google.gerrit.server.restapi.project; package com.google.gerrit.server.restapi.project;
import static com.google.gerrit.entities.RefNames.isConfigRef; import com.google.common.base.Preconditions;
import com.google.gerrit.extensions.common.Input; import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.extensions.restapi.RestModifyView;
@@ -27,6 +25,7 @@ import com.google.gerrit.server.project.TagResource;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.lib.Constants;
@Singleton @Singleton
public class DeleteTag implements RestModifyView<TagResource, Input> { public class DeleteTag implements RestModifyView<TagResource, Input> {
@@ -43,10 +42,7 @@ public class DeleteTag implements RestModifyView<TagResource, Input> {
throws RestApiException, IOException, PermissionBackendException { throws RestApiException, IOException, PermissionBackendException {
String tag = RefUtil.normalizeTagRef(resource.getTagInfo().ref); String tag = RefUtil.normalizeTagRef(resource.getTagInfo().ref);
if (isConfigRef(tag)) { Preconditions.checkState(tag.startsWith(Constants.R_TAGS));
// Never allow to delete the meta config branch.
throw new MethodNotAllowedException("not allowed to delete " + tag);
}
deleteRef.deleteSingleRef(resource.getProjectState(), tag); deleteRef.deleteSingleRef(resource.getProjectState(), tag);
return Response.none(); return Response.none();