diff --git a/scripts/arcanist.php b/scripts/arcanist.php index 2ba80ef9..96e42d56 100755 --- a/scripts/arcanist.php +++ b/scripts/arcanist.php @@ -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"; } diff --git a/src/workflow/alias/ArcanistAliasWorkflow.php b/src/workflow/alias/ArcanistAliasWorkflow.php index 70cbfda1..b90ce4b4 100644 --- a/src/workflow/alias/ArcanistAliasWorkflow.php +++ b/src/workflow/alias/ArcanistAliasWorkflow.php @@ -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); } diff --git a/src/workflow/alias/__init__.php b/src/workflow/alias/__init__.php index e5111ce4..0a1286d1 100644 --- a/src/workflow/alias/__init__.php +++ b/src/workflow/alias/__init__.php @@ -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'); diff --git a/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php b/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php index 1f0d7941..8698be38 100644 --- a/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php +++ b/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php @@ -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); }