Ejemplo n.º 1
0
def create_repo(request, repo_name, template_dir=None):
    auth = request.auth_backend
    settings = get_settings(request)
    if auth.has_permission(request.user, ('kittygit','create')):
        auth.add_permission(request.user, ('kittygit','write','%s/%s' % (request.user, repo_name)))
        auth.add_permission(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)
            clone_path = '/'.join([request.user, repo_name]) + '.git'
            return Success({
                'message':"""
                    Successfully created a new repository. Clone it at %s:%s
                """.strip() % (clone_base, clone_path),
                'clone_path':clone_path
            })
        else:
            raise NappingCatException('Create repo failed.') 
    raise KittyGitUnauthorized('You don\'t have permission to create a repo.')
Ejemplo n.º 2
0
def fork_repo(request, repo):
    settings = get_settings(request)
    auth = request.auth_backend
    username, repo_name = repo.split('/', 1)
    if auth.has_permission(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.user, ('kittygit', 'write', '%s/%s' % (request.user, repo_name)))
            auth.add_permission(request.user, ('kittygit', 'read', '%s/%s' % (request.user, repo_name)))
            auth.add_permission(username, ('kittygit', 'read', '%s/%s' % (request.user, repo_name)))
            clone_base = get_clone_base_url(settings)
            return Success({'message':"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.º 3
0
    def test_use_hostname(self):
        settings = {
            'user':'******' % random.randint(1,100),
        }

        results = utils.get_clone_base_url(settings)
        self.assertEqual('%s@%s.local' % (settings['user'], socket.gethostname()), results)
Ejemplo n.º 4
0
 def test_use_defaults(self):
     settings = {
         'user':'******' % random.randint(1,100),
         'host':'host-%d' % random.randint(1,100),
     }
     results = utils.get_clone_base_url(settings)
     self.assertEqual('%s@%s' % (settings['user'], settings['host']), results)
Ejemplo n.º 5
0
 def test_getlogin_fails(self):
     settings = {
         'host':'host-%d' % random.randint(1,100),
     }
     _mox = mox.Mox()
     _mox.StubOutWithMock(os, 'getlogin')
     random_user = '******' % random.randint(1,100)
     os.getlogin().AndRaise(OSError)
     _mox.ReplayAll()
     results = utils.get_clone_base_url(settings)
     self.assertEqual('%s@%s' % (utils.DEFAULT_USER_NAME, settings['host']), results)
     _mox.UnsetStubs()
Ejemplo n.º 6
0
 def test_uses_getlogin(self):
     settings = {
         'host':'host-%d' % random.randint(1,100),
     }
     _mox = mox.Mox()
     _mox.StubOutWithMock(os, 'getlogin')
     random_user = '******' % random.randint(1,100)
     os.getlogin().AndReturn(random_user)
     _mox.ReplayAll()
     results = utils.get_clone_base_url(settings)
     self.assertEqual('%s@%s' % (random_user, settings['host']), results)
     _mox.UnsetStubs()