]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Explicitly check for supported VCS
authorJoshua Spence <josh@joshuaspence.com>
Mon, 2 Feb 2015 19:54:22 +0000 (06:54 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 2 Feb 2015 19:54:22 +0000 (06:54 +1100)
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

scripts/arcanist.php
src/workflow/ArcanistAmendWorkflow.php
src/workflow/ArcanistBookmarkWorkflow.php
src/workflow/ArcanistCommitWorkflow.php
src/workflow/ArcanistLandWorkflow.php
src/workflow/ArcanistRevertWorkflow.php
src/workflow/ArcanistWorkflow.php

index dc22d7b6361c61ec44612a577c442a547254647c..737a01a82aa588726f527260b7636f6f2c600d38 100755 (executable)
@@ -202,6 +202,16 @@ try {
     $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_conduit         = $workflow->requiresConduit();
   $need_auth            = $workflow->requiresAuthentication();
index d9be2865e146d9900ab42c2b13554e732e82aac7..334ff9d266a065d27928398257ccbfaae6cff9f3 100644 (file)
@@ -188,7 +188,7 @@ EOTEXT
     return 0;
   }
 
-  protected function getSupportedRevisionControlSystems() {
+  public function getSupportedRevisionControlSystems() {
     return array('git', 'hg');
   }
 
index 16c71accdfa3e5b46cf60ac56c17a22997168ae6..131c21b3cb876f99e20b7e690c5f4cb772c9bba2 100644 (file)
@@ -25,12 +25,11 @@ EOTEXT
       );
   }
 
+  public function getSupportedRevisionControlSystems() {
+    return array('hg');
+  }
+
   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();
   }
 
index dbd2b7910d8797bffca3c8b0cdf964a711d00e5a..6ac44102315d201f8d4cc104cbe644ff36a8e375 100644 (file)
@@ -65,12 +65,6 @@ EOTEXT
   public function run() {
     $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'));
     if (!$revision_id) {
       $revisions = $repository_api->loadWorkingCopyDifferentialRevisions(
@@ -271,7 +265,7 @@ EOTEXT
     }
   }
 
-  protected function getSupportedRevisionControlSystems() {
+  public function getSupportedRevisionControlSystems() {
     return array('svn');
   }
 
index d18af1830440afd276b44b5c3d248b7cdba87cb6..69c498ec6f13dac85d28a8f37f6f82bce33a0bce 100644 (file)
@@ -239,13 +239,6 @@ EOTEXT
     $this->isGit = $repository_api instanceof ArcanistGitAPI;
     $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) {
       $repository = $this->loadProjectRepository();
       $this->isGitSvn = (idx($repository, 'vcs') == 'svn');
@@ -1141,7 +1134,7 @@ EOTEXT
     }
   }
 
-  protected function getSupportedRevisionControlSystems() {
+  public function getSupportedRevisionControlSystems() {
     return array('git', 'hg');
   }
 
index 823a2802e6dcd659e6da6e2296d2d1286e75fc51..205c91d3ee10b3ae324f308e0982b5d7f2df8169 100644 (file)
@@ -29,7 +29,7 @@ EOTEXT
     );
   }
 
-  protected function getSupportedRevisionControlSystems() {
+  public function getSupportedRevisionControlSystems() {
     return array('git', 'hg');
   }
 
index 56fad6dc92836246f28a25e5216fb984f799d0ab..7c5719866c6e261b05afbe7d5f8a9923d0cc7554 100644 (file)
@@ -1215,7 +1215,7 @@ abstract class ArcanistWorkflow extends Phobject {
     return array();
   }
 
-  protected function getSupportedRevisionControlSystems() {
+  public function getSupportedRevisionControlSystems() {
     return array('git', 'hg', 'svn');
   }