Add handling when duplicated branch part cannot be created (#1692)

Add handling when duplicated branch cannot be created because a part of the name already exists as a branch
This commit is contained in:
Florian Scholdei
2021-06-09 14:58:59 +02:00
committed by GitHub
parent 35fe536170
commit f274b7f4b2
8 changed files with 112 additions and 9 deletions

View File

@@ -257,6 +257,38 @@ public class BranchRootResourceTest extends RepositoryTestBase {
verify(branchCommandBuilder, never()).branch(anyString());
}
@Test
public void shouldNotCreateBranchIfDirectoryAsBranchAlreadyExists() throws Exception {
when(branchesCommandBuilder.getBranches()).thenReturn(new Branches(createBranch("existing_branch")));
MockHttpRequest request = MockHttpRequest
.post("/" + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/branches/")
.content("{\"name\": \"existing_branch/abc\"}".getBytes())
.contentType(VndMediaType.BRANCH_REQUEST);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(409, response.getStatus());
verify(branchCommandBuilder, never()).branch(anyString());
}
@Test
public void shouldNotCreateBranchIfBranchWithDirectoryAlreadyExists() throws Exception {
when(branchesCommandBuilder.getBranches()).thenReturn(new Branches(createBranch("existing_branch/abc")));
MockHttpRequest request = MockHttpRequest
.post("/" + RepositoryRootResource.REPOSITORIES_PATH_V2 + "space/repo/branches/")
.content("{\"name\": \"existing_branch\"}".getBytes())
.contentType(VndMediaType.BRANCH_REQUEST);
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertEquals(409, response.getStatus());
verify(branchCommandBuilder, never()).branch(anyString());
}
@Test
public void shouldFailForMissingParentBranch() throws Exception {
when(branchesCommandBuilder.getBranches()).thenReturn(new Branches(createBranch("existing_branch")));