changeset 1550:6f468ba37650 beta

fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 12 Oct 2011 14:43:46 +0200
parents d6cb805c92fd
children cb8321dfc771 662173ba1846
files rhodecode/model/forms.py rhodecode/model/repo.py
diffstat 2 files changed, 27 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/model/forms.py	Tue Oct 11 20:59:41 2011 -0500
+++ b/rhodecode/model/forms.py	Wed Oct 12 14:43:46 2011 +0200
@@ -250,7 +250,7 @@
                 gr = Group.get(value.get('repo_group'))
                 group_path = gr.full_path
                 # value needs to be aware of group name in order to check
-                # db key This is an actuall just the name to store in the
+                # db key This is an actual just the name to store in the
                 # database
                 repo_name_full = group_path + Group.url_sep() + repo_name
             else:
@@ -259,25 +259,32 @@
 
 
             value['repo_name_full'] = repo_name_full
-            if old_data.get('repo_name') != repo_name_full or not edit:
+            rename = old_data.get('repo_name') != repo_name_full
+            create = not edit
+            if  rename or create:
 
                 if group_path != '':
                     if RepoModel().get_by_repo_name(repo_name_full,):
                         e_dict = {'repo_name':_('This repository already '
-                                                'exists in group "%s"') %
+                                                'exists in a group "%s"') %
                                   gr.group_name}
                         raise formencode.Invalid('', value, state,
                                                  error_dict=e_dict)
+                elif Group.get_by_group_name(repo_name_full):
+                        e_dict = {'repo_name':_('There is a group with this'
+                                                ' name already "%s"') %
+                                  repo_name_full}
+                        raise formencode.Invalid('', value, state,
+                                                 error_dict=e_dict)
 
-                else:
-                    if RepoModel().get_by_repo_name(repo_name_full):
+                elif RepoModel().get_by_repo_name(repo_name_full):
                         e_dict = {'repo_name':_('This repository '
                                                 'already exists')}
                         raise formencode.Invalid('', value, state,
                                                  error_dict=e_dict)
+
             return value
 
-
     return _ValidRepoName
 
 def ValidForkName():
--- a/rhodecode/model/repo.py	Tue Oct 11 20:59:41 2011 -0500
+++ b/rhodecode/model/repo.py	Wed Oct 12 14:43:46 2011 +0200
@@ -305,7 +305,7 @@
         :param parent_id:
         :param clone_uri:
         """
-        from rhodecode.lib.utils import is_valid_repo
+        from rhodecode.lib.utils import is_valid_repo,is_valid_repos_group
 
         if new_parent_id:
             paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
@@ -316,12 +316,20 @@
         repo_path = os.path.join(*map(lambda x:safe_str(x),
                                 [self.repos_path, new_parent_path, repo_name]))
 
-        if is_valid_repo(repo_path, self.repos_path) is False:
-            log.info('creating repo %s in %s @ %s', repo_name, repo_path,
-                     clone_uri)
-            backend = get_backend(alias)
+        
+        # check if this path is not a repository
+        if is_valid_repo(repo_path, self.repos_path):
+            raise Exception('This path %s is a valid repository' % repo_path)
 
-            backend(repo_path, create=True, src_url=clone_uri)
+        # check if this path is a group
+        if is_valid_repos_group(repo_path, self.repos_path):
+            raise Exception('This path %s is a valid group' % repo_path)
+                
+        log.info('creating repo %s in %s @ %s', repo_name, repo_path,
+                 clone_uri)
+        backend = get_backend(alias)
+
+        backend(repo_path, create=True, src_url=clone_uri)
 
 
     def __rename_repo(self, old, new):