Esempio n. 1
0
def fork_repo(request, repo):
    settings = get_settings(request)

    username, repo_name = repo.split('/', 1)
    if auth.has_permission(request, request.user, ('kittygit', 'read', '%s/%s' % (username, repo_name))):

        to_repo_dir = get_full_repo_dir(settings, request.user, repo_name)
        from_repo_dir = get_full_repo_dir(settings, username, repo_name)
        success = operations.fork_repository(
            settings.get('git', 'git'),
            request.stdin,
            request.stdout,
            request.stderr,
            from_repo_dir,
            to_repo_dir
        )
        if success:
            auth.add_permission(request, request.user, ('kittygit', 'write', '%s/%s' % (request.user, repo_name)))
            auth.add_permission(request, request.user, ('kittygit', 'read', '%s/%s' % (request.user, repo_name)))
            auth.add_permission(request, username, ('kittygit', 'read', '%s/%s' % (request.user, repo_name)))
            clone_base = get_clone_base_url(settings)
            return "Repository '%s' successfully forked.\nClone it at '%s:%s/%s.git'" % (repo, clone_base, request.user, repo_name)
        else:
            raise NappingCatException('Fork failed.')
    else:
        raise KittyGitUnauthorized("You don't have permission to read %s.git. Sorry!" % repo)
Esempio n. 2
0
def create_repo(request, repo_name, template_dir=None):
    settings = get_settings(request)
    if auth.has_permission(request, request.user, ('kittygit','create')):
        auth.add_permission(request, request.user, ('kittygit','write','%s/%s' % (request.user, repo_name)))
        auth.add_permission(request, request.user, ('kittygit', 'read', '%s/%s' % (request.user, repo_name)))

        full_repo_dir = get_full_repo_dir(settings, request.user, repo_name)
        success = operations.create_repository(
            settings.get('git', 'git'),
            request.stdin,
            request.stdout,
            request.stderr,
            full_repo_dir,
            template_dir
        )
        if success:
            clone_base = get_clone_base_url(settings)
            return """
                Successfully created a new repository. Clone it at %s:%s.git
            """.strip() % (clone_base, '/'.join([request.user, repo_name]))
        else:
            raise NappingCatException('Create repo failed.') 
    raise KittyGitUnauthorized('You don\'t have permission to create a repo.')