Commits

Marcin Kuzminski committed 6f468ba

fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group

Comments (0)

Files changed (2)

rhodecode/model/forms.py

                 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:
 
 
             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():

rhodecode/model/repo.py

         :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())
         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):