]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow 'arc' to run without '.arcconfig'
authorepriestley <git@epriestley.com>
Mon, 7 May 2012 22:24:58 +0000 (15:24 -0700)
committerepriestley <git@epriestley.com>
Mon, 7 May 2012 22:24:58 +0000 (15:24 -0700)
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.

  - Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
  - Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
  - Make all the workflows handle "no project ID" at least somewhat gracefully.

Test Plan:
  - Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
  - Ran "arc upload" and "arc download" from my desktop.
  - Ran "arc paste" from somewhere random.
  - Cleared my config and hit the error, got useful instructions.

Reviewers: btrahan, csilvers

Reviewed By: csilvers

CC: aran
Differential Revision: https://secure.phabricator.com/D2424

scripts/arcanist.php
src/repository/api/subversion/ArcanistSubversionAPI.php
src/workflow/base/ArcanistBaseWorkflow.php
src/workflow/close-revision/ArcanistCloseRevisionWorkflow.php
src/workflow/get-config/ArcanistGetConfigWorkflow.php
src/workflow/set-config/ArcanistSetConfigWorkflow.php
src/workingcopyidentity/ArcanistWorkingCopyIdentity.php

index f73fdc297b209e0d76893351e96999bb6eab572c..785f4f8a8a4fee902e6c83acb512838ca5977b39 100755 (executable)
@@ -146,6 +146,7 @@ try {
   }
 
   $user_config = ArcanistBaseWorkflow::readUserConfigurationFile();
+  $global_config = ArcanistBaseWorkflow::readGlobalArcConfig();
 
   $config = $working_copy->getConfig('arcanist_configuration');
   if ($config) {
@@ -200,24 +201,25 @@ try {
   $need_conduit       = $need_conduit ||
                         $need_auth;
   $need_working_copy  = $need_working_copy ||
-                        $need_conduit ||
                         $need_repository_api;
 
   if ($need_working_copy) {
     if (!$working_copy->getProjectRoot()) {
       throw new ArcanistUsageException(
-        "There is no '.arcconfig' file in this directory or any parent ".
-        "directory. Create a '.arcconfig' file to configure this project ".
-        "for use with Arcanist.");
+        "This command must be run in a Git, Mercurial or Subversion working ".
+        "copy.");
     }
     $workflow->setWorkingCopy($working_copy);
   }
 
-
   if ($force_conduit) {
     $conduit_uri = $force_conduit;
   } else {
-    $conduit_uri = $working_copy->getConduitURI();
+    if ($working_copy->getConduitURI()) {
+      $conduit_uri = $working_copy->getConduitURI();
+    } else {
+      $conduit_uri = idx($global_config, 'default');
+    }
   }
   if ($conduit_uri) {
     // Set the URI path to '/api/'. TODO: Originally, I contemplated letting
@@ -233,9 +235,17 @@ try {
 
   if ($need_conduit) {
     if (!$conduit_uri) {
-      throw new ArcanistUsageException(
-        "No Conduit URI is specified in the .arcconfig file for this project. ".
-        "Specify the Conduit URI for the host Differential is running on.");
+
+      $message = phutil_console_format(
+        "This command requires arc to connect to a Phabricator install, but ".
+        "no Phabricator installation is configured. To configure a ".
+        "Phabricator URI:\n\n".
+        "  - set a default location with `arc set-config default <uri>`; or\n".
+        "  - specify '--conduit-uri=uri' explicitly; or\n".
+        "  - run 'arc' in a working copy with an '.arcconfig'.\n");
+
+      $message = phutil_console_wrap($message);
+      throw new ArcanistUsageException($message);
     }
     $workflow->establishConduit();
   }
index 84986d1471d3995c106380311b4e2b5df55fa3be..ca987ba8b3bce1ee93633755f38089b04c050eb7 100644 (file)
@@ -537,6 +537,10 @@ EODIFF;
     // this directory and belong to the same project.
 
     $project = $this->getWorkingCopyIdentity()->getProjectID();
+    if (!$project) {
+      return array();
+    }
+
     $results = $conduit->callMethodSynchronous(
       'differential.query',
       $query + array(
index fe5ca40b60400e0b047fdceb05de073ca2d61b41..cfb5e204ecc5668578be2bfe5e375246f6815843 100644 (file)
@@ -927,11 +927,11 @@ abstract class ArcanistBaseWorkflow {
     }
   }
 
-  protected function readGlobalArcConfig() {
+  public static function readGlobalArcConfig() {
     return idx(self::readUserConfigurationFile(), 'config', array());
   }
 
-  protected function writeGlobalArcConfig(array $options) {
+  public static function writeGlobalArcConfig(array $options) {
     $config = self::readUserConfigurationFile();
     $config['config'] = $options;
     self::writeUserConfigurationFile($config);
@@ -1102,12 +1102,21 @@ abstract class ArcanistBaseWorkflow {
       return $this->repositoryEncoding;
     }
 
+    $default = 'UTF-8';
+
+    $project_id = $this->getWorkingCopy()->getProjectID();
+    if (!$project_id) {
+      return $default;
+    }
+
     $project_info = $this->getConduit()->callMethodSynchronous(
       'arcanist.projectinfo',
       array(
-        'name' => $this->getWorkingCopy()->getProjectID(),
+        'name' => $project_id,
       ));
-    $this->repositoryEncoding = nonempty($project_info['encoding'], 'UTF-8');
+
+    $this->repositoryEncoding = nonempty($project_info['encoding'], $default);
+
     return $this->repositoryEncoding;
   }
 
index cb24081d61a2a3f7982556c34d21a33aa72d8622..390dea10d2d4a549c0216a8feb9e41102bcae4de 100644 (file)
@@ -127,14 +127,17 @@ EOTEXT
 
       $actually_close = true;
       if ($is_finalize) {
-        $project_info = $conduit->callMethodSynchronous(
-          'arcanist.projectinfo',
-          array(
-            'name' => $this->getWorkingCopy()->getProjectID(),
-          ));
-        if ($project_info['tracked'] ||
-            $revision['status'] != $status_accepted) {
-          $actually_close = false;
+        $project_id = $this->getWorkingCopy()->getProjectID();
+        if ($project_id) {
+          $project_info = $conduit->callMethodSynchronous(
+            'arcanist.projectinfo',
+            array(
+              'name' => $project_id,
+            ));
+          if ($project_info['tracked'] ||
+              $revision['status'] != $status_accepted) {
+            $actually_close = false;
+          }
         }
       }
       if ($actually_close) {
index 2dac758eea6f1fc26ab79a19dbb1d225adfefd56..497fc409465e92c0344f7421bd109e0639d03039 100644 (file)
@@ -48,7 +48,7 @@ EOTEXT
   public function run() {
     $argv = $this->getArgument('argv');
 
-    $config = $this->readGlobalArcConfig();
+    $config = self::readGlobalArcConfig();
     if ($argv) {
       $keys = $argv;
     } else {
index d6bee4bd9057243b094cb30da0f108046388d516..4effedde970ec64207ec187a8f2d64d3dfae50db 100644 (file)
@@ -53,7 +53,7 @@ EOTEXT
       throw new ArcanistUsageException("Specify a key and a value.");
     }
 
-    $config = $this->readGlobalArcConfig();
+    $config = self::readGlobalArcConfig();
 
     $key = $argv[0];
     $val = $argv[1];
@@ -65,7 +65,7 @@ EOTEXT
 
     if (!strlen($val)) {
       unset($config[$key]);
-      $this->writeGlobalArcConfig($config);
+      self::writeGlobalArcConfig($config);
 
       if ($old === null) {
         echo "Deleted key '{$key}'.\n";
@@ -74,7 +74,7 @@ EOTEXT
       }
     } else {
       $config[$key] = $val;
-      $this->writeGlobalArcConfig($config);
+      self::writeGlobalArcConfig($config);
 
       if ($old === null) {
         echo "Set key '{$key}' = '{$val}'.\n";
index 0468074dc97f6c3e9f352f4129ad3867347c9aab..c2400404edf814d4519057619eaedb9deb525c30 100644 (file)
@@ -40,6 +40,23 @@ final class ArcanistWorkingCopyIdentity {
       $project_root = $dir;
       break;
     }
+
+    if (!$project_root) {
+      foreach (Filesystem::walkToRoot($path) as $dir) {
+        $try = array(
+          $dir.'/.svn',
+          $dir.'/.hg',
+          $dir.'/.git',
+        );
+        foreach ($try as $trydir) {
+          if (Filesystem::pathExists($trydir)) {
+            $project_root = $dir;
+            break 2;
+          }
+        }
+      }
+    }
+
     return new ArcanistWorkingCopyIdentity($project_root, $config);
   }