Merge "Disallow branch creation under 'refs/for/'"
This commit is contained in:
commit
51d0c163dc
@ -23,6 +23,7 @@ import com.google.gerrit.reviewdb.Branch;
|
||||
import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.ReceiveCommits;
|
||||
import com.google.gerrit.server.git.ReplicationQueue;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
@ -90,7 +91,8 @@ class AddBranch extends Handler<ListBranchesResult> {
|
||||
|
||||
@Override
|
||||
public ListBranchesResult call() throws NoSuchProjectException,
|
||||
InvalidNameException, InvalidRevisionException, IOException {
|
||||
InvalidNameException, InvalidRevisionException, IOException,
|
||||
BranchCreationNotAllowedException {
|
||||
final ProjectControl projectControl =
|
||||
projectControlFactory.controlFor(projectName);
|
||||
|
||||
@ -104,6 +106,9 @@ class AddBranch extends Handler<ListBranchesResult> {
|
||||
if (!Repository.isValidRefName(refname)) {
|
||||
throw new InvalidNameException();
|
||||
}
|
||||
if (refname.startsWith(ReceiveCommits.NEW_CHANGE)) {
|
||||
throw new BranchCreationNotAllowedException(ReceiveCommits.NEW_CHANGE);
|
||||
}
|
||||
|
||||
final Branch.NameKey name = new Branch.NameKey(projectName, refname);
|
||||
final RefControl refControl = projectControl.controlForRef(name);
|
||||
|
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2010 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.httpd.rpc.project;
|
||||
|
||||
public class BranchCreationNotAllowedException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String MESSAGE = "Branch creation is not allowed under: ";
|
||||
|
||||
public BranchCreationNotAllowedException(final String refnamePrefix) {
|
||||
super(MESSAGE + refnamePrefix);
|
||||
}
|
||||
}
|
@ -102,7 +102,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(ReceiveCommits.class);
|
||||
|
||||
private static final String NEW_CHANGE = "refs/for/";
|
||||
public static final String NEW_CHANGE = "refs/for/";
|
||||
private static final Pattern NEW_PATCHSET =
|
||||
Pattern.compile("^refs/changes/(?:[0-9][0-9]/)?([1-9][0-9]*)(?:/new)?$");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user