def requestReceived(self, command, raw_pathname, params): path = compose_path(self.factory.root, raw_pathname) if command == b'git-upload-pack': subcmd = b'upload-pack' elif command == b'git-receive-pack': subcmd = b'receive-pack' else: self.die(b'Unsupported command in request') return cmd = b'git' args = [b'git', subcmd] if params.pop(b'turnip-stateless-rpc', None): args.append(b'--stateless-rpc') if params.pop(b'turnip-advertise-refs', None): args.append(b'--advertise-refs') args.append(path) env = {} if subcmd == b'receive-pack' and self.factory.hookrpc_handler: # This is a write operation, so prepare config, hooks, the hook # RPC server, and the environment variables that link them up. ensure_config(path) self.hookrpc_key = str(uuid.uuid4()) self.factory.hookrpc_handler.registerKey( self.hookrpc_key, raw_pathname, []) ensure_hooks(path) env[b'TURNIP_HOOK_RPC_SOCK'] = self.factory.hookrpc_sock env[b'TURNIP_HOOK_RPC_KEY'] = self.hookrpc_key self.peer = GitProcessProtocol(self) reactor.spawnProcess(self.peer, cmd, args, env=env)
def test_absolute(self): # Even absolute paths are contained. self.assertEqual( b'/foo/bar/baz/quux', helpers.compose_path(b'/foo/bar', b'/baz/quux'))
def test_normalises(self): # Paths are normalised. self.assertEqual( b'/foo/bar/baz/quux', helpers.compose_path(b'///foo/.//bar', b'//baz/..//baz/./quux'))
def test_basic(self): # The path is resolved within the given root tree. self.assertEqual( b'/foo/bar/baz/quux', helpers.compose_path(b'/foo/bar', b'baz/quux'))