diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -116,19 +116,21 @@ def make_map(config): #settings actions m.connect('repo_stats', "/repos_stats/{repo_name:.*}", - action="repo_stats", conditions=dict(method=["DELETE"], - function=check_repo)) + action="repo_stats", conditions=dict(method=["DELETE"], + function=check_repo)) m.connect('repo_cache', "/repos_cache/{repo_name:.*}", - action="repo_cache", conditions=dict(method=["DELETE"], + action="repo_cache", conditions=dict(method=["DELETE"], + function=check_repo)) + m.connect('repo_public_journal',"/repos_public_journal/{repo_name:.*}", + action="repo_public_journal", conditions=dict(method=["PUT"], function=check_repo)) - m.connect('repo_public_journal', - "/repos_public_journal/{repo_name:.*}", - action="repo_public_journal", conditions=dict(method=["PUT"], - function=check_repo)) m.connect('repo_pull', "/repo_pull/{repo_name:.*}", - action="repo_pull", conditions=dict(method=["PUT"], - function=check_repo)) - + action="repo_pull", conditions=dict(method=["PUT"], + function=check_repo)) + m.connect('repo_as_fork', "/repo_as_fork/{repo_name:.*}", + action="repo_as_fork", conditions=dict(method=["PUT"], + function=check_repo)) + with rmap.submapper(path_prefix=ADMIN_PREFIX, controller='admin/repos_groups') as m: m.connect("repos_groups", "/repos_groups", diff --git a/rhodecode/controllers/admin/repos.py b/rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py +++ b/rhodecode/controllers/admin/repos.py @@ -111,6 +111,10 @@ class ReposController(BaseController): c.repo_last_rev) * 100) defaults = RepoModel()._get_defaults(repo_name) + + c.repos_list = [('', _('--REMOVE FORK--'))] + c.repos_list += [(x.repo_id, x.repo_name) for x in + Repository.query().order_by(Repository.repo_name).all()] return defaults @HasPermissionAllDecorator('hg.admin') @@ -380,6 +384,28 @@ class ReposController(BaseController): return redirect(url('edit_repo', repo_name=repo_name)) @HasPermissionAllDecorator('hg.admin') + def repo_as_fork(self, repo_name): + """ + Mark given repository as a fork of another + + :param repo_name: + """ + try: + fork_id = request.POST.get('id_fork_of') + repo = ScmModel().mark_as_fork(repo_name, fork_id, + self.rhodecode_user.username) + fork = repo.fork.repo_name if repo.fork else _('Nothing') + Session.commit() + h.flash(_('Marked repo %s as fork of %s' % (repo_name,fork)), + category='success') + except Exception, e: + raise + h.flash(_('An error occurred during this operation'), + category='error') + + return redirect(url('edit_repo', repo_name=repo_name)) + + @HasPermissionAllDecorator('hg.admin') def show(self, repo_name, format='html'): """GET /repos/repo_name: Show a specific item""" # url('repo', repo_name=ID) diff --git a/rhodecode/model/__init__.py b/rhodecode/model/__init__.py --- a/rhodecode/model/__init__.py +++ b/rhodecode/model/__init__.py @@ -89,5 +89,4 @@ class BaseModel(object): else: if instance: raise Exception('given object must be int or Instance' - ' of %s got %s' % (type(cls), - type(instance))) + ' of %s got %s' % (type(cls), type(instance))) diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py --- a/rhodecode/model/scm.py +++ b/rhodecode/model/scm.py @@ -117,6 +117,18 @@ class ScmModel(BaseModel): Generic Scm Model """ + def __get_repo(self, instance): + cls = Repository + if isinstance(instance, cls): + return instance + elif isinstance(instance, int) or str(instance).isdigit(): + return cls.get(instance) + elif isinstance(instance, basestring): + return cls.get_by_repo_name(instance) + elif instance: + raise Exception('given object must be int, basestr or Instance' + ' of %s got %s' % (type(cls), type(instance))) + @LazyProperty def repos_path(self): """ @@ -279,6 +291,13 @@ class ScmModel(BaseModel): return self.sa.query(Repository)\ .filter(Repository.fork_id == repo_id).count() + def mark_as_fork(self, repo, fork, user): + repo = self.__get_repo(repo) + fork = self.__get_repo(fork) + repo.fork = fork + self.sa.add(repo) + return repo + def pull_changes(self, repo_name, username): dbrepo = Repository.get_by_repo_name(repo_name) clone_uri = dbrepo.clone_uri diff --git a/rhodecode/templates/admin/repos/repo_edit.html b/rhodecode/templates/admin/repos/repo_edit.html --- a/rhodecode/templates/admin/repos/repo_edit.html +++ b/rhodecode/templates/admin/repos/repo_edit.html @@ -131,14 +131,13 @@ ${h.form(url('repo_stats', repo_name=c.repo_info.repo_name),method='delete')}