mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01: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:
@@ -62,7 +62,7 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Optional;
|
||||
|
||||
import static sonia.scm.AlreadyExistsException.alreadyExists;
|
||||
import static sonia.scm.BranchAlreadyExistsException.branchAlreadyExists;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
@@ -254,7 +254,7 @@ public class BranchRootResource {
|
||||
String parentName = branchRequest.getParent();
|
||||
try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
|
||||
if (branchExists(branchName, repositoryService)) {
|
||||
throw alreadyExists(entity(Branch.class, branchName).in(Repository.class, namespace + "/" + name));
|
||||
throw branchAlreadyExists(entity(Branch.class, branchName).in(Repository.class, namespace + "/" + name));
|
||||
}
|
||||
Repository repository = repositoryService.getRepository();
|
||||
RepositoryPermissions.push(repository).check();
|
||||
@@ -275,7 +275,16 @@ public class BranchRootResource {
|
||||
.getBranches()
|
||||
.getBranches()
|
||||
.stream()
|
||||
.anyMatch(branch -> branchName.equals(branch.getName()));
|
||||
.anyMatch(branch -> branchName.equals(branch.getName())
|
||||
|| branchNamespaceAlreadyExistsInGitRepo(branchName, branch.getName(), repositoryService));
|
||||
}
|
||||
|
||||
private boolean branchNamespaceAlreadyExistsInGitRepo(String branchName, String branchName2, RepositoryService repositoryService) {
|
||||
if (repositoryService.getRepository().getType().equals("hg")) {
|
||||
return false;
|
||||
}
|
||||
return (branchName.contains("/") && branchName2.equals(branchName.substring(0, branchName.indexOf("/"))))
|
||||
|| (branchName2.contains("/") && branchName.equals(branchName2.substring(0, branchName2.indexOf("/"))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user