Example #1
0
 def test_empty(self):
     update_server_info(self.repo)
     with open(os.path.join(self.path, ".git", "info", "refs"), 'rb') as f:
         self.assertEqual(b'', f.read())
     with open(os.path.join(self.path, ".git", "objects", "info", "packs"),
               'rb') as f:
         self.assertEqual(b'', f.read())
Example #2
0
 def test_simple(self):
     commit_id = self.repo.do_commit(message="foo", committer="Joe Example <*****@*****.**>", ref="refs/heads/foo")
     update_server_info(self.repo)
     ref_text = open(os.path.join(self.path, ".git", "info", "refs"), "r").read()
     self.assertEqual(ref_text, "%s\trefs/heads/foo\n" % commit_id)
     packs_text = open(os.path.join(self.path, ".git", "objects", "info", "packs"), "r").read()
     self.assertEqual(packs_text, "")
Example #3
0
 def test_empty(self):
     update_server_info(self.repo)
     with open(os.path.join(self.path, ".git", "info", "refs"), 'rb') as f:
         self.assertEqual(b'', f.read())
     p = os.path.join(self.path, ".git", "objects", "info", "packs")
     with open(p, 'rb') as f:
         self.assertEqual(b'', f.read())
Example #4
0
def run(event, context):
    dulwich.client.get_ssh_vendor = git.KeyParamikoSSHVendor
    repo = porcelain.clone(
        "remote_repository",
        "/tmp/repo"
    )
    server.update_server_info(repo)
    with open("/tmp/repo/.git/info/refs") as r:
        print(r.read())
Example #5
0
 def test_simple(self):
     commit_id = self.repo.do_commit(
         message=b"foo", committer=b"Joe Example <*****@*****.**>", ref=b"refs/heads/foo"
     )
     update_server_info(self.repo)
     with open(os.path.join(self.path, ".git", "info", "refs"), "rb") as f:
         self.assertEqual(f.read(), commit_id + b"\trefs/heads/foo\n")
     with open(os.path.join(self.path, ".git", "objects", "info", "packs"), "rb") as f:
         self.assertEqual(f.read(), b"")
Example #6
0
 def test_empty(self):
     update_server_info(self.repo)
     self.assertEqual(
         "",
         open(os.path.join(self.path, ".git", "info", "refs"), 'r').read())
     self.assertEqual(
         "",
         open(os.path.join(self.path, ".git", "objects", "info", "packs"),
              'r').read())
Example #7
0
 def test_simple(self):
     commit_id = self.repo.do_commit(
         message="foo",
         committer="Joe Example <*****@*****.**>",
         ref="refs/heads/foo")
     update_server_info(self.repo)
     ref_text = open(os.path.join(self.path, ".git", "info", "refs"), 'r').read()
     self.assertEquals(ref_text, "%s\trefs/heads/foo\n" % commit_id)
     packs_text = open(os.path.join(self.path, ".git", "objects", "info", "packs"), 'r').read()
     self.assertEquals(packs_text, "")
Example #8
0
 def test_simple(self):
     commit_id = self.repo.do_commit(
         message=b"foo",
         committer=b"Joe Example <*****@*****.**>",
         ref=b"refs/heads/foo")
     update_server_info(self.repo)
     with open(os.path.join(self.path, ".git", "info", "refs"), 'rb') as f:
         self.assertEqual(f.read(), commit_id + b'\trefs/heads/foo\n')
     with open(os.path.join(self.path, ".git", "objects", "info", "packs"), 'rb') as f:
         self.assertEqual(f.read(), b'')
Example #9
0
 def _update_server_info(self):
     """
     runs gits update-server-info command in this repo instance
     """
     from dulwich.server import update_server_info
     try:
         update_server_info(self._repo)
     except OSError as e:
         if e.errno not in [errno.ENOENT, errno.EROFS]:
             raise
         # Workaround for dulwich crashing on for example its own dulwich/tests/data/repos/simple_merge.git/info/refs.lock
         log.error('Ignoring %s running update-server-info: %s', type(e).__name__, e)
Example #10
0
    def backend(self, req, environ):
        """
        WSGI Response producer for HTTP POST Git Smart HTTP requests.
        Reads commands and data from HTTP POST's body.
        returns an iterator obj with contents of git command's
        response to stdout
        """
        _git_path = kallithea.CONFIG.get('git_path', 'git')
        git_command = self._get_fixedpath(req.path_info)
        if git_command not in self.commands:
            log.debug('command %s not allowed', git_command)
            return exc.HTTPMethodNotAllowed()

        if 'CONTENT_LENGTH' in environ:
            inputstream = FileWrapper(environ['wsgi.input'],
                                      req.content_length)
        else:
            inputstream = environ['wsgi.input']

        gitenv = dict(os.environ)
        # forget all configs
        gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
        cmd = [
            _git_path, git_command[4:], '--stateless-rpc', self.content_path
        ]
        log.debug('handling cmd %s', cmd)
        try:
            out = subprocessio.SubprocessIOChunker(
                cmd,
                inputstream=inputstream,
                env=gitenv,
                cwd=self.content_path,
            )
        except EnvironmentError as e:
            log.error(traceback.format_exc())
            raise exc.HTTPExpectationFailed()

        if git_command in ['git-receive-pack']:
            # updating refs manually after each push.
            # Needed for pre-1.7.0.4 git clients using regular HTTP mode.
            from kallithea.lib.vcs import get_repo
            from dulwich.server import update_server_info
            repo = get_repo(self.content_path)
            if repo:
                update_server_info(repo._repo)

        resp = Response()
        resp.content_type = 'application/x-%s-result' % git_command.encode(
            'utf-8')
        resp.charset = None
        resp.app_iter = out
        return resp
Example #11
0
 def _update_server_info(self):
     """
     runs gits update-server-info command in this repo instance
     """
     from dulwich.server import update_server_info
     try:
         update_server_info(self._repo)
     except OSError as e:
         if e.errno not in [errno.ENOENT, errno.EROFS]:
             raise
         # Workaround for dulwich crashing on for example its own dulwich/tests/data/repos/simple_merge.git/info/refs.lock
         log.error('Ignoring %s running update-server-info: %s',
                   type(e).__name__, e)
Example #12
0
    def backend(self, request, environ):
        """
        WSGI Response producer for HTTP POST Git Smart HTTP requests.
        Reads commands and data from HTTP POST's body.
        returns an iterator obj with contents of git command's
        response to stdout
        """
        _git_path = kallithea.CONFIG.get('git_path', 'git')
        git_command = self._get_fixedpath(request.path_info)
        if git_command not in self.commands:
            log.debug('command %s not allowed', git_command)
            return exc.HTTPMethodNotAllowed()

        if 'CONTENT_LENGTH' in environ:
            inputstream = FileWrapper(environ['wsgi.input'],
                                      request.content_length)
        else:
            inputstream = environ['wsgi.input']

        gitenv = dict(os.environ)
        # forget all configs
        gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
        cmd = [_git_path, git_command[4:], '--stateless-rpc', self.content_path]
        log.debug('handling cmd %s', cmd)
        try:
            out = subprocessio.SubprocessIOChunker(
                cmd,
                inputstream=inputstream,
                env=gitenv,
                cwd=self.content_path,
            )
        except EnvironmentError as e:
            log.error(traceback.format_exc())
            raise exc.HTTPExpectationFailed()

        if git_command in [u'git-receive-pack']:
            # updating refs manually after each push.
            # Needed for pre-1.7.0.4 git clients using regular HTTP mode.
            from kallithea.lib.vcs import get_repo
            from dulwich.server import update_server_info
            repo = get_repo(self.content_path)
            if repo:
                update_server_info(repo._repo)

        resp = Response()
        resp.content_type = 'application/x-%s-result' % git_command.encode('utf8')
        resp.charset = None
        resp.app_iter = out
        return resp
Example #13
0
 def update_server_info(self):
     if not self.is_bare:
         return
     update_server_info(self.repo)
Example #14
0
 def update_server_info(self):
     if not self.is_bare:
         return
     update_server_info(self.repo)
Example #15
0
                cmd,
                inputstream=inputstream,
                **opts
            )
        except EnvironmentError, e:
            log.error(traceback.format_exc())
            raise exc.HTTPExpectationFailed()

        if git_command in [u'git-receive-pack']:
            # updating refs manually after each push.
            # Needed for pre-1.7.0.4 git clients using regular HTTP mode.
            from kallithea.lib.vcs import get_repo
            from dulwich.server import update_server_info
            repo = get_repo(self.content_path)
            if repo:
                update_server_info(repo._repo)

        resp = Response()
        resp.content_type = 'application/x-%s-result' % git_command.encode('utf8')
        resp.charset = None
        resp.app_iter = out
        return resp

    def __call__(self, environ, start_response):
        request = Request(environ)
        _path = self._get_fixedpath(request.path_info)
        if _path.startswith('info/refs'):
            app = self.inforefs
        elif [a for a in self.valid_accepts if a in request.accept]:
            app = self.backend
        try:
Example #16
0
 def test_empty(self):
     update_server_info(self.repo)
     self.assertEqual("",
         open(os.path.join(self.path, ".git", "info", "refs"), 'r').read())
     self.assertEqual("",
         open(os.path.join(self.path, ".git", "objects", "info", "packs"), 'r').read())
Example #17
0
def run(event, context):
    dulwich.client.get_ssh_vendor = git.KeyParamikoSSHVendor
    repo = porcelain.clone("remote_repository", "/tmp/repo")
    server.update_server_info(repo)
    with open("/tmp/repo/.git/info/refs") as r:
        print(r.read())
Example #18
0
 def update_server_info(self, wire):
     repo = self._factory.repo(wire)
     update_server_info(repo)
Example #19
0
 def _update_server_info(self):
     """
     runs gits update-server-info command in this repo instance
     """
     from dulwich.server import update_server_info
     update_server_info(self._repo)
Example #20
0
            log.debug('handling cmd %s' % cmd)
            out = subprocessio.SubprocessIOChunker(cmd,
                                                   inputstream=inputstream,
                                                   **opts)
        except EnvironmentError, e:
            log.error(traceback.format_exc())
            raise exc.HTTPExpectationFailed()

        if git_command in [u'git-receive-pack']:
            # updating refs manually after each push.
            # Needed for pre-1.7.0.4 git clients using regular HTTP mode.
            from kallithea.lib.vcs import get_repo
            from dulwich.server import update_server_info
            repo = get_repo(self.content_path)
            if repo:
                update_server_info(repo._repo)

        resp = Response()
        resp.content_type = 'application/x-%s-result' % git_command.encode(
            'utf8')
        resp.charset = None
        resp.app_iter = out
        return resp

    def __call__(self, environ, start_response):
        request = Request(environ)
        _path = self._get_fixedpath(request.path_info)
        if _path.startswith('info/refs'):
            app = self.inforefs
        elif [a for a in self.valid_accepts if a in request.accept]:
            app = self.backend
Example #21
0
 def update_server_info(self, wire):
     repo = self._factory.repo(wire)
     update_server_info(repo)