1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

Explicitly check for supported VCS

Summary: Instead of having an `ArcanistWorkflow` subclass explicitly throw an exception when run in an unsupported VCS, consolidate this code and move it to `arcanist.php`. In doing so, we lose some specificity in some of the error messages, but this otherwise feels cleaner. We could consider adding a `getUnsupportedRevisionControlSystemMessage()` method to provide a more tailored error message. Depends on D11604.

Test Plan:
Ran `arc bookmark` in a `git` working copy:

```
Usage Exception: `arc bookmark` is only supported under hg.
```

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11550
This commit is contained in:
Joshua Spence 2015-02-03 06:54:22 +11:00
parent 52277fc06f
commit e4be031778
7 changed files with 19 additions and 23 deletions

View file

@ -202,6 +202,16 @@ try {
$workflow->setConduitTimeout($conduit_timeout); $workflow->setConduitTimeout($conduit_timeout);
} }
$supported_vcs_types = $workflow->getSupportedRevisionControlSystems();
if (!in_array($working_copy->getVCSType(), $supported_vcs_types)) {
throw new ArcanistUsageException(
pht(
'`%s %s` is only supported under %s.',
'arc',
$workflow->getWorkflowName(),
implode(', ', $supported_vcs_types)));
}
$need_working_copy = $workflow->requiresWorkingCopy(); $need_working_copy = $workflow->requiresWorkingCopy();
$need_conduit = $workflow->requiresConduit(); $need_conduit = $workflow->requiresConduit();
$need_auth = $workflow->requiresAuthentication(); $need_auth = $workflow->requiresAuthentication();

View file

@ -188,7 +188,7 @@ EOTEXT
return 0; return 0;
} }
protected function getSupportedRevisionControlSystems() { public function getSupportedRevisionControlSystems() {
return array('git', 'hg'); return array('git', 'hg');
} }

View file

@ -25,12 +25,11 @@ EOTEXT
); );
} }
public function getSupportedRevisionControlSystems() {
return array('hg');
}
public function run() { public function run() {
$repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistMercurialAPI)) {
throw new ArcanistUsageException(
'arc bookmark is only supported under Mercurial.');
}
return parent::run(); return parent::run();
} }

View file

@ -65,12 +65,6 @@ EOTEXT
public function run() { public function run() {
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
if (!($repository_api instanceof ArcanistSubversionAPI)) {
throw new ArcanistUsageException(
"'arc commit' is only supported under svn.");
}
$revision_id = $this->normalizeRevisionID($this->getArgument('revision')); $revision_id = $this->normalizeRevisionID($this->getArgument('revision'));
if (!$revision_id) { if (!$revision_id) {
$revisions = $repository_api->loadWorkingCopyDifferentialRevisions( $revisions = $repository_api->loadWorkingCopyDifferentialRevisions(
@ -271,7 +265,7 @@ EOTEXT
} }
} }
protected function getSupportedRevisionControlSystems() { public function getSupportedRevisionControlSystems() {
return array('svn'); return array('svn');
} }

View file

@ -239,13 +239,6 @@ EOTEXT
$this->isGit = $repository_api instanceof ArcanistGitAPI; $this->isGit = $repository_api instanceof ArcanistGitAPI;
$this->isHg = $repository_api instanceof ArcanistMercurialAPI; $this->isHg = $repository_api instanceof ArcanistMercurialAPI;
if (!$this->isGit && !$this->isHg) {
throw new ArcanistUsageException(
pht(
"'arc land' only supports Git and Mercurial. For Subversion, try ".
"'arc commit'."));
}
if ($this->isGit) { if ($this->isGit) {
$repository = $this->loadProjectRepository(); $repository = $this->loadProjectRepository();
$this->isGitSvn = (idx($repository, 'vcs') == 'svn'); $this->isGitSvn = (idx($repository, 'vcs') == 'svn');
@ -1141,7 +1134,7 @@ EOTEXT
} }
} }
protected function getSupportedRevisionControlSystems() { public function getSupportedRevisionControlSystems() {
return array('git', 'hg'); return array('git', 'hg');
} }

View file

@ -29,7 +29,7 @@ EOTEXT
); );
} }
protected function getSupportedRevisionControlSystems() { public function getSupportedRevisionControlSystems() {
return array('git', 'hg'); return array('git', 'hg');
} }

View file

@ -1215,7 +1215,7 @@ abstract class ArcanistWorkflow extends Phobject {
return array(); return array();
} }
protected function getSupportedRevisionControlSystems() { public function getSupportedRevisionControlSystems() {
return array('git', 'hg', 'svn'); return array('git', 'hg', 'svn');
} }