mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-04 02:09:31 +02:00
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:
@@ -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")));
|
||||
|
||||
Reference in New Issue
Block a user