From faf983614cd5be20561aa139593d2c5539496485 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 2 Dec 2016 06:20:12 -0800 Subject: [PATCH] Improve error messages for running `git clone` against a Mercurial repository Summary: Fixes T11938. Note that there's a subcase here: if you `hg clone` or `svn checkout` a short `/source/` URI that ends in `.git`, we miss the lookup and don't get this far, so you still get a generic error message. Hopefully it is clear enough on its own that `proto://.../blah.git` is, in fact, a Git repository, since it says ".git" at the end. If that doesn't prove to be true, we can be more surgical about this. Test Plan: ``` $ git clone ssh://local@localvault.phacility.com/source/quack.notgit/ Cloning into 'quack.notgit'... phabricator-ssh-exec: This repository ("quack.notgit") is not a Git repository. Use "hg" to interact with this repository. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ``` ``` $ hg clone ssh://local@localvault.phacility.com/source/phabx remote: phabricator-ssh-exec: This repository ("phabx") is not a Mercurial repository. Use "git" to interact with this repository. abort: no suitable response from remote hg! ``` Reviewers: chad Reviewed By: chad Maniphest Tasks: T11938 Differential Revision: https://secure.phabricator.com/D16976 --- .../diffusion/ssh/DiffusionGitSSHWorkflow.php | 10 ++++++++++ .../ssh/DiffusionMercurialServeSSHWorkflow.php | 10 ++++++++++ .../diffusion/ssh/DiffusionSSHWorkflow.php | 6 ++++++ .../ssh/DiffusionSubversionServeSSHWorkflow.php | 10 ++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/applications/diffusion/ssh/DiffusionGitSSHWorkflow.php b/src/applications/diffusion/ssh/DiffusionGitSSHWorkflow.php index 52a8478fdc..6de16e723d 100644 --- a/src/applications/diffusion/ssh/DiffusionGitSSHWorkflow.php +++ b/src/applications/diffusion/ssh/DiffusionGitSSHWorkflow.php @@ -35,4 +35,14 @@ abstract class DiffusionGitSSHWorkflow } } + protected function raiseWrongVCSException( + PhabricatorRepository $repository) { + throw new Exception( + pht( + 'This repository ("%s") is not a Git repository. Use "%s" to '. + 'interact with this repository.', + $repository->getDisplayName(), + $repository->getVersionControlSystem())); + } + } diff --git a/src/applications/diffusion/ssh/DiffusionMercurialServeSSHWorkflow.php b/src/applications/diffusion/ssh/DiffusionMercurialServeSSHWorkflow.php index 15dd9d7c6b..4508ae53da 100644 --- a/src/applications/diffusion/ssh/DiffusionMercurialServeSSHWorkflow.php +++ b/src/applications/diffusion/ssh/DiffusionMercurialServeSSHWorkflow.php @@ -119,4 +119,14 @@ final class DiffusionMercurialServeSSHWorkflow return $raw_message; } + protected function raiseWrongVCSException( + PhabricatorRepository $repository) { + throw new Exception( + pht( + 'This repository ("%s") is not a Mercurial repository. Use "%s" to '. + 'interact with this repository.', + $repository->getDisplayName(), + $repository->getVersionControlSystem())); + } + } diff --git a/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php b/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php index 0115858832..0e5ad7bbe1 100644 --- a/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php +++ b/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php @@ -43,6 +43,8 @@ abstract class DiffusionSSHWorkflow extends PhabricatorSSHWorkflow { */ abstract protected function identifyRepository(); abstract protected function executeRepositoryOperations(); + abstract protected function raiseWrongVCSException( + PhabricatorRepository $repository); protected function getBaseRequestPath() { return $this->baseRequestPath; @@ -199,6 +201,10 @@ abstract class DiffusionSSHWorkflow extends PhabricatorSSHWorkflow { $repository->getDisplayName())); } + if ($repository->getVersionControlSystem() != $vcs) { + $this->raiseWrongVCSException($repository); + } + return $repository; } diff --git a/src/applications/diffusion/ssh/DiffusionSubversionServeSSHWorkflow.php b/src/applications/diffusion/ssh/DiffusionSubversionServeSSHWorkflow.php index 3a8b516443..f2a932f2bb 100644 --- a/src/applications/diffusion/ssh/DiffusionSubversionServeSSHWorkflow.php +++ b/src/applications/diffusion/ssh/DiffusionSubversionServeSSHWorkflow.php @@ -449,4 +449,14 @@ final class DiffusionSubversionServeSSHWorkflow return $path; } + protected function raiseWrongVCSException( + PhabricatorRepository $repository) { + throw new Exception( + pht( + 'This repository ("%s") is not a Subversion repository. Use "%s" to '. + 'interact with this repository.', + $repository->getDisplayName(), + $repository->getVersionControlSystem())); + } + }