Ejemplo 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)
Ejemplo n.º 2
0
 def test_actually_forks_repository(self):
     from_dir, to_dir = ".%d" % random.randint(1,100), ".o%d" % random.randint(1,100)
     self.cleanup_dirs = [from_dir, to_dir]
     git = 'git'
     with open('/dev/null','w') as output:
         operations.create_repository(git, output, output, output, from_dir)
         result = operations.fork_repository(git, output, output, output, from_dir, to_dir)
         self.assertTrue(isinstance(result, bool))
         self.assertTrue(result)
         self.assertTrue(os.path.exists('/'.join([to_dir, 'config'])))