]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow defining aliases in .arcconfig.
authorBen Gertzfield <beng@fb.com>
Tue, 10 Apr 2012 18:29:25 +0000 (11:29 -0700)
committerBen Gertzfield <beng@fb.com>
Tue, 10 Apr 2012 19:42:13 +0000 (12:42 -0700)
Summary:
For Objective-C repositories, we want to provide aliases to
arc diff --amend-autofixes by default.

This adds the ability to define aliases in .arcconfig (overridden
by any specified in the user config, of course).

Test Plan:
Tested defining alias with nothing in .arcconfig, with
an alias in .arcconfig.  Tested arc alias outside of working
repository.

Reviewers: epriestley

Reviewed By: epriestley

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

scripts/arcanist.php
src/workflow/alias/ArcanistAliasWorkflow.php
src/workflow/alias/__init__.php
src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php

index 2ba80ef91c28ee5a773dade97193a40d372e349d..96e42d56f87b9e6252822ba2bde89b684bf4e5f1 100755 (executable)
@@ -168,7 +168,8 @@ try {
     list($new_command, $args) = ArcanistAliasWorkflow::resolveAliases(
       $command,
       $config,
-      $args);
+      $args,
+      $working_copy);
 
     if ($new_command) {
       $workflow = $config->buildWorkflow($new_command);
@@ -179,7 +180,7 @@ try {
         "Unknown command '{$command}'. Try 'arc help'.");
     } else {
       if ($config_trace_mode) {
-        $aliases = ArcanistAliasWorkflow::getAliases();
+        $aliases = ArcanistAliasWorkflow::getAliases($working_copy);
         $target = implode(' ', idx($aliases, $command, array()));
         echo "[alias: 'arc {$command}' -> 'arc {$target}']\n";
       }
index 70cbfda10714b0f5f555517bcbe9f150962ae6b4..b90ce4b4aebd7f7c3bfd36deb9b2e01a7f59f559 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 /**
- * Show which revision or revisions are in the working copy.
+ * Manages aliases for commands with options.
  *
  * @group workflow
  */
@@ -62,9 +62,14 @@ EOTEXT
     );
   }
 
-  public static function getAliases() {
-    $config = self::readUserConfigurationFile();
-    return idx($config, 'aliases', array());
+  public static function getAliases($working_copy) {
+    $working_copy_config_aliases = $working_copy->getConfig('aliases');
+    if (!$working_copy_config_aliases) {
+      $working_copy_config_aliases = array();
+    }
+    $user_config_aliases =
+      idx(self::readUserConfigurationFile(), 'aliases', array());
+    return $user_config_aliases + $working_copy_config_aliases;
   }
 
   private function writeAliases(array $aliases) {
@@ -74,8 +79,10 @@ EOTEXT
   }
 
   public function run() {
-
-    $aliases = self::getAliases();
+    // We might not be in a working directory, so we don't want to require a
+    // working copy identity here.
+    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(getcwd());
+    $aliases = self::getAliases($working_copy);
 
     $argv = $this->getArgument('argv');
     if (count($argv) == 0) {
@@ -132,9 +139,10 @@ EOTEXT
   public static function resolveAliases(
     $command,
     ArcanistConfiguration $config,
-    array $argv) {
+    array $argv,
+    ArcanistWorkingCopyIdentity $working_copy) {
 
-    $aliases = ArcanistAliasWorkflow::getAliases();
+    $aliases = ArcanistAliasWorkflow::getAliases($working_copy);
     if (!isset($aliases[$command])) {
       return array(null, $argv);
     }
index e5111ce4123f7eee0639e2644854e334086a03a7..0a1286d15da75a58686d663b9ab330c56533bbc7 100644 (file)
@@ -9,6 +9,7 @@
 phutil_require_module('arcanist', 'exception/usage');
 phutil_require_module('arcanist', 'exception/usage/userabort');
 phutil_require_module('arcanist', 'workflow/base');
+phutil_require_module('arcanist', 'workingcopyidentity');
 
 phutil_require_module('phutil', 'console');
 phutil_require_module('phutil', 'utils');
index 1f0d7941f241abd767767b6e7b6301c6eacb3a8d..8698be38e32177a48de6055fab31014bf14b94de 100644 (file)
@@ -100,7 +100,8 @@ EOTEXT
       }
 
       // Also permit autocompletion of "arc alias" commands.
-      foreach (ArcanistAliasWorkflow::getAliases() as $key => $value) {
+      foreach (
+        ArcanistAliasWorkflow::getAliases($working_copy) as $key => $value) {
         $complete[] = $key;
       }
 
@@ -112,7 +113,8 @@ EOTEXT
         list($new_command, $new_args) = ArcanistAliasWorkflow::resolveAliases(
           $argv[1],
           $arc_config,
-          array_slice($argv, 2));
+          array_slice($argv, 2),
+          $working_copy);
         if ($new_command) {
           $workflow = $arc_config->buildWorkflow($new_command);
         }