]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Autocomplete branches to "arc land"
authorepriestley <git@epriestley.com>
Mon, 23 Apr 2012 21:09:29 +0000 (14:09 -0700)
committerepriestley <git@epriestley.com>
Mon, 23 Apr 2012 21:09:29 +0000 (14:09 -0700)
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

src/repository/api/base/ArcanistRepositoryAPI.php
src/workflow/land/ArcanistLandWorkflow.php
src/workflow/shell-complete/ArcanistShellCompleteWorkflow.php

index f40dab4ae65cd3af23a0347d0f943b306f0a3a94..5db9e2d6ad0290de2c3df2ce04329132ece27844 100644 (file)
@@ -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);
   }
index 928f62761c8ec4d20d5ac0cc00ff05e2189eb9d5..a5cf3ed1edfece874a046dff909d370fdea15358 100644 (file)
@@ -25,7 +25,7 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
 
   public function getCommandSynopses() {
     return phutil_console_format(<<<EOTEXT
-      **land** [__options__] __branch__ [--onto __master__]
+      **land** [__options__] [__branch__] [--onto __master__]
 EOTEXT
       );
   }
@@ -36,7 +36,8 @@ EOTEXT
 
           Land an accepted change (currently sitting in local feature branch
           __branch__) onto __master__ and push it to the remote. Then, delete
-          the feature branch.
+          the feature branch. If you omit __branch__, the current branch will
+          be used.
 
           In mutable repositories, this will perform a --squash merge (the
           entire branch will be represented by one commit on __master__). In
@@ -106,7 +107,20 @@ EOTEXT
   }
 
   public function run() {
+    $repository_api = $this->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);
index 8698be38e32177a48de6055fab31014bf14b94de..584dcf47cb3d095029111e65904cc205214318e4 100644 (file)
@@ -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;
       }
     }