diff --git a/src/applications/diffusion/request/DiffusionGitRequest.php b/src/applications/diffusion/request/DiffusionGitRequest.php index 4dfc22be5d..8cc99b600d 100644 --- a/src/applications/diffusion/request/DiffusionGitRequest.php +++ b/src/applications/diffusion/request/DiffusionGitRequest.php @@ -12,9 +12,7 @@ final class DiffusionGitRequest extends DiffusionRequest { protected function didInitialize() { $repository = $this->getRepository(); - if (!Filesystem::pathExists($repository->getLocalPath())) { - $this->raiseCloneException(); - } + $this->validateWorkingCopy($repository->getLocalPath()); if (!$this->commit) { return; diff --git a/src/applications/diffusion/request/DiffusionMercurialRequest.php b/src/applications/diffusion/request/DiffusionMercurialRequest.php index 891b534a8b..79a828ee3f 100644 --- a/src/applications/diffusion/request/DiffusionMercurialRequest.php +++ b/src/applications/diffusion/request/DiffusionMercurialRequest.php @@ -12,9 +12,7 @@ final class DiffusionMercurialRequest extends DiffusionRequest { protected function didInitialize() { $repository = $this->getRepository(); - if (!Filesystem::pathExists($repository->getLocalPath())) { - $this->raiseCloneException(); - } + $this->validateWorkingCopy($repository->getLocalPath()); // Expand abbreviated hashes to full hashes so "/rXnnnn" (i.e., fewer than // 40 characters) works correctly. diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php index 94610f3790..e7f5005fe0 100644 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -544,6 +544,30 @@ abstract class DiffusionRequest { return $result; } + /** + * Check that the working copy of the repository is present and readable. + * + * @param string Path to the working copy. + */ + protected function validateWorkingCopy($path) { + if (!is_readable(dirname($path))) { + $this->raisePermissionException(); + } + + if (!Filesystem::pathExists($path)) { + $this->raiseCloneException(); + } + } + + protected function raisePermissionException() { + $host = php_uname('n'); + $callsign = $this->getRepository()->getCallsign(); + throw new DiffusionSetupException( + "The clone of this repository ('{$callsign}') on the local machine " . + "('{$host}') could not be read. Ensure that the repository is in a " . + "location where the web server has read permissions."); + } + protected function raiseCloneException() { $host = php_uname('n'); $callsign = $this->getRepository()->getCallsign();