protected function loadRepositoryWithPath($path) { $viewer = $this->getUser(); $info = PhabricatorRepository::parseRepositoryServicePath($path); if ($info === null) { throw new Exception(pht('Unrecognized repository path "%s". Expected a path like "%s" ' . 'or "%s".', $path, '/diffusion/X/', '/diffusion/123/')); } $identifier = $info['identifier']; $base = $info['base']; $this->baseRequestPath = $base; $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withIdentifiers(array($identifier))->needURIs(true)->executeOne(); if (!$repository) { throw new Exception(pht('No repository "%s" exists!', $identifier)); } $protocol = PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH; if (!$repository->canServeProtocol($protocol, false)) { throw new Exception(pht('This repository ("%s") is not available over SSH.', $repository->getDisplayName())); } return $repository; }
private function getRequestDirectoryPath(PhabricatorRepository $repository) { $request = $this->getRequest(); $request_path = $request->getRequestURI()->getPath(); $info = PhabricatorRepository::parseRepositoryServicePath($request_path, $repository->getVersionControlSystem()); $base_path = $info['path']; // For Git repositories, strip an optional directory component if it // isn't the name of a known Git resource. This allows users to clone // repositories as "/diffusion/X/anything.git", for example. if ($repository->isGit()) { $known = array('info', 'git-upload-pack', 'git-receive-pack'); foreach ($known as $key => $path) { $known[$key] = preg_quote($path, '@'); } $known = implode('|', $known); if (preg_match('@^/([^/]+)/(' . $known . ')(/|$)@', $base_path)) { $base_path = preg_replace('@^/([^/]+)@', '', $base_path); } } return $base_path; }
protected function loadRepositoryWithPath($path) { $viewer = $this->getUser(); $info = PhabricatorRepository::parseRepositoryServicePath($path); if ($info === null) { throw new Exception(pht('Unrecognized repository path "%s". Expected a path like "%s" ' . 'or "%s".', $path, '/diffusion/X/', '/diffusion/123/')); } $identifier = $info['identifier']; $base = $info['base']; $this->baseRequestPath = $base; $repository = id(new PhabricatorRepositoryQuery())->setViewer($viewer)->withIdentifiers(array($identifier))->executeOne(); if (!$repository) { throw new Exception(pht('No repository "%s" exists!', $identifier)); } switch ($repository->getServeOverSSH()) { case PhabricatorRepository::SERVE_READONLY: case PhabricatorRepository::SERVE_READWRITE: // If we have read or read/write access, proceed for now. We will // check write access when the user actually issues a write command. break; case PhabricatorRepository::SERVE_OFF: default: throw new Exception(pht('This repository ("%s") is not available over SSH.', $repository->getDisplayName())); } return $repository; }