From 9c4c1de512002193fbfcef4c751c061de6f69410 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 23 Apr 2012 14:09:29 -0700 Subject: [PATCH] Autocomplete branches to "arc land" Summary: - Add branch name tab completion to "arc land". - Default to landing the current branch. - This is a little bit hacky but not too terrible. I'm planning to move the whole thing to PhutilArgumentParser at some point so that'll be an opportunity for a big refactor. Test Plan: Hit tab, landed this branch. Reviewers: zeeg, btrahan, vrana, jungejason Reviewed By: btrahan CC: aran, kdeggelman Differential Revision: https://secure.phabricator.com/D2293 --- .../api/base/ArcanistRepositoryAPI.php | 5 ++++ src/workflow/land/ArcanistLandWorkflow.php | 23 ++++++++++----- .../ArcanistShellCompleteWorkflow.php | 29 +++++++++++++------ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/repository/api/base/ArcanistRepositoryAPI.php b/src/repository/api/base/ArcanistRepositoryAPI.php index f40dab4a..5db9e2d6 100644 --- a/src/repository/api/base/ArcanistRepositoryAPI.php +++ b/src/repository/api/base/ArcanistRepositoryAPI.php @@ -177,6 +177,11 @@ abstract class ArcanistRepositoryAPI { ConduitClient $conduit, array $query); + public function getAllBranches() { + // TODO: Implement for Mercurial/SVN and make abstract. + return array(); + } + public function hasLocalCommit($commit) { throw new ArcanistCapabilityNotSupportedException($this); } diff --git a/src/workflow/land/ArcanistLandWorkflow.php b/src/workflow/land/ArcanistLandWorkflow.php index 928f6276..a5cf3ed1 100644 --- a/src/workflow/land/ArcanistLandWorkflow.php +++ b/src/workflow/land/ArcanistLandWorkflow.php @@ -25,7 +25,7 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow { public function getCommandSynopses() { return phutil_console_format(<<getRepositoryAPI(); + if (!($repository_api instanceof ArcanistGitAPI)) { + throw new ArcanistUsageException("'arc land' only supports git."); + } + $branch = $this->getArgument('branch'); + if (empty($branch)) { + $branch = $repository_api->getBranchName(); + if ($branch) { + echo "Landing current branch '{$branch}'.\n"; + $branch = array($branch); + } + } + if (count($branch) !== 1) { throw new ArcanistUsageException( "Specify exactly one branch to land changes from."); @@ -128,11 +142,6 @@ EOTEXT $use_squash = !$this->isHistoryImmutable(); } - $repository_api = $this->getRepositoryAPI(); - if (!($repository_api instanceof ArcanistGitAPI)) { - throw new ArcanistUsageException("'arc land' only supports git."); - } - list($err) = $repository_api->execManualLocal( 'rev-parse --verify %s', $branch); diff --git a/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php b/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php index 8698be38..584dcf47 100644 --- a/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php +++ b/src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php @@ -171,20 +171,31 @@ EOTEXT $cur = idx($argv, $pos, ''); $any_match = false; - foreach ($output as $possible) { - if (!strncmp($possible, $cur, strlen($cur))) { - $any_match = true; + + if (strlen($cur)) { + foreach ($output as $possible) { + if (!strncmp($possible, $cur, strlen($cur))) { + $any_match = true; + } } } if (!$any_match && isset($arguments['*'])) { - // TODO: the '*' specifier should probably have more details about - // whether or not it is a list of files. Since it almost always is in - // practice, assume FILE for now. - echo "FILE\n"; - } else { - echo implode(' ', $output)."\n"; + // TODO: This is mega hacktown but something else probably breaks + // if we use a rich argument specification; fix it when we move to + // PhutilArgumentParser since everything will need to be tested then + // anyway. + if ($arguments['*'] == 'branch' && isset($repository_api)) { + $branches = $repository_api->getAllBranches(); + $branches = ipull($branches, 'name'); + $output = $branches; + } else { + $output = array("FILE"); + } } + + echo implode(' ', $output)."\n"; + return 0; } }