mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-26 16:30:50 +01:00
Check on duplicate name for rename
Add check whether namespace and name already exist when renaming a repository.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.ConfigurationException;
|
||||
import sonia.scm.HandlerEventType;
|
||||
import sonia.scm.ManagerDaoAdapter;
|
||||
@@ -183,7 +184,7 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
},
|
||||
newRepository -> {
|
||||
if (repositoryDAO.contains(newRepository.getNamespaceAndName())) {
|
||||
throw alreadyExists(entity(newRepository.getClass(), newRepository.getNamespaceAndName().logString()));
|
||||
throw alreadyExists(entity(newRepository.getNamespaceAndName()));
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -292,10 +293,16 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
|
||||
public Repository rename(Repository repository, String newNamespace, String newName) {
|
||||
|
||||
NamespaceAndName newNamespaceAndName = new NamespaceAndName(newNamespace, newName);
|
||||
|
||||
if (hasNamespaceOrNameNotChanged(repository, newNamespace, newName)) {
|
||||
throw new NoChangesMadeException(repository);
|
||||
}
|
||||
|
||||
if (this.get(newNamespaceAndName) != null){
|
||||
throw AlreadyExistsException.alreadyExists(entity(NamespaceAndName.class, newNamespaceAndName.logString()));
|
||||
}
|
||||
|
||||
Repository changedRepository = repository.clone();
|
||||
if (!Strings.isNullOrEmpty(newName)) {
|
||||
changedRepository.setName(newName);
|
||||
|
||||
Reference in New Issue
Block a user