Merge changes I32bba5a0,I86e46cf3,I7593ff70,Id6d004e8
* changes: CreateBranch: Test rejection if branch name in URL and input mismatch CreateBranch: Test that branches cannot be created with invalid names CreateBranch: Test that branches cannot be created under 'refs/for/' CreateBranch: Test creation of a conflicting branch
This commit is contained in:
@@ -45,6 +45,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
|||||||
import com.google.gerrit.server.events.RefReceivedEvent;
|
import com.google.gerrit.server.events.RefReceivedEvent;
|
||||||
import com.google.gerrit.server.git.validators.RefOperationValidationListener;
|
import com.google.gerrit.server.git.validators.RefOperationValidationListener;
|
||||||
import com.google.gerrit.server.git.validators.ValidationMessage;
|
import com.google.gerrit.server.git.validators.ValidationMessage;
|
||||||
|
import com.google.gerrit.server.util.MagicBranch;
|
||||||
import com.google.gerrit.server.validators.ValidationException;
|
import com.google.gerrit.server.validators.ValidationException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -140,6 +141,20 @@ public class CreateBranchIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void conflictingBranchAlreadyExists_Conflict() throws Exception {
|
||||||
|
assertCreateSucceeds(testBranch);
|
||||||
|
BranchNameKey testBranch2 = BranchNameKey.create(project, testBranch.branch() + "/foo/bar");
|
||||||
|
assertCreateFails(
|
||||||
|
testBranch2,
|
||||||
|
ResourceConflictException.class,
|
||||||
|
"Cannot create branch \""
|
||||||
|
+ testBranch2.branch()
|
||||||
|
+ "\" since it conflicts with branch \""
|
||||||
|
+ testBranch.branch()
|
||||||
|
+ "\"");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBranchByProjectOwner() throws Exception {
|
public void createBranchByProjectOwner() throws Exception {
|
||||||
grantOwner();
|
grantOwner();
|
||||||
@@ -313,6 +328,22 @@ public class CreateBranchIT extends AbstractDaemonTest {
|
|||||||
"invalid revision \"invalid\trevision\"");
|
"invalid revision \"invalid\trevision\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cannotCreateBranchInMagicBranchNamespace() throws Exception {
|
||||||
|
assertCreateFails(
|
||||||
|
BranchNameKey.create(project, MagicBranch.NEW_CHANGE + "foo"),
|
||||||
|
BadRequestException.class,
|
||||||
|
"not allowed to create branches under \"" + MagicBranch.NEW_CHANGE + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cannotCreateBranchWithInvalidName() throws Exception {
|
||||||
|
assertCreateFails(
|
||||||
|
BranchNameKey.create(project, RefNames.REFS_HEADS),
|
||||||
|
BadRequestException.class,
|
||||||
|
"invalid branch name \"" + RefNames.REFS_HEADS + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createBranchLeadingSlashesAreRemoved() throws Exception {
|
public void createBranchLeadingSlashesAreRemoved() throws Exception {
|
||||||
BranchNameKey expectedNameKey = BranchNameKey.create(project, "test");
|
BranchNameKey expectedNameKey = BranchNameKey.create(project, "test");
|
||||||
@@ -334,6 +365,17 @@ public class CreateBranchIT extends AbstractDaemonTest {
|
|||||||
.isEqualTo(expectedNameKey.branch());
|
.isEqualTo(expectedNameKey.branch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void branchNameInInputMustMatchBranchNameInUrl() throws Exception {
|
||||||
|
BranchInput branchInput = new BranchInput();
|
||||||
|
branchInput.ref = "foo";
|
||||||
|
BadRequestException ex =
|
||||||
|
assertThrows(
|
||||||
|
BadRequestException.class,
|
||||||
|
() -> gApi.projects().name(project.get()).branch("bar").create(branchInput));
|
||||||
|
assertThat(ex).hasMessageThat().isEqualTo("ref must match URL");
|
||||||
|
}
|
||||||
|
|
||||||
private void blockCreateReference() throws Exception {
|
private void blockCreateReference() throws Exception {
|
||||||
projectOperations
|
projectOperations
|
||||||
.project(project)
|
.project(project)
|
||||||
|
Reference in New Issue
Block a user