]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix "arc branch" to work if you are on "(no branch)" add revision IDs
authorepriestley <git@epriestley.com>
Wed, 29 Jun 2011 20:21:30 +0000 (13:21 -0700)
committerepriestley <git@epriestley.com>
Wed, 29 Jun 2011 20:30:44 +0000 (13:30 -0700)
Summary:
If you checkout some commit you end up on "(no branch)" which currently breaks
the parser. Ignore that, and add revision IDs to the output. They aren't very
big and I hate flags so I didn't add a flag for this. You can add a flag to turn
them off if you really want.

Test Plan:
Ran "arc branch" and "arc branch --by-status" from a "(no branch)" working copy.

Reviewed By: slawekbiel
Reviewers: slawekbiel, ahupp, jungejason, tuomaspelkonen, aran, schrockn
CC: aran, slawekbiel
Differential Revision: 555

src/branch/BranchInfo.php
src/repository/api/git/ArcanistGitAPI.php
src/workflow/branch/ArcanistBranchWorkflow.php

index 54beae10cc631156003a2546d570ebec481e17eb..38881c3cd2931035674f4962fc42d8212d5e0d3e 100644 (file)
@@ -92,7 +92,7 @@ class BranchInfo {
     return $this->status;
   }
 
-  public function getRevisionId() {
+  public function getRevisionID() {
     return $this->revisionID;
   }
 
@@ -104,6 +104,14 @@ class BranchInfo {
     return $this->commitSubject;
   }
 
+  public function getCommitDisplayName() {
+    if ($this->revisionID) {
+      return 'D'.$this->revisionID.': '.$this->commitSubject;
+    } else {
+      return $this->commitSubject;
+    }
+  }
+
   public function getCommitAuthor() {
     return $this->commitAuthor;
   }
index 3c466b0da767dbf7fbe35ce0a0371b92e4d5bdf0..e69f77853aa5da84c96eba9f14abb9dd0824a468 100644 (file)
@@ -410,11 +410,17 @@ class ArcanistGitAPI extends ArcanistRepositoryAPI {
     $result = array();
     foreach ($lines as $line) {
       $match = array();
-      $branch = array();
-      preg_match('/^(\*?)\s*(\S+)/', $line, $match);
-      $branch['current'] = !empty($match[1]);
-      $branch['name'] = $match[2];
-      $result[] = $branch;
+      preg_match('/^(\*?)\s*(.*)$/', $line, $match);
+      $name = $match[2];
+      if ($name == '(no branch)') {
+        // Just ignore this, we could theoretically try to figure out the ref
+        // and treat it like a real branch but that's sort of ridiculous.
+        continue;
+      }
+      $result[] = array(
+        'current' => !empty($match[1]),
+        'name'    => $name,
+      );
     }
     $all_names = ipull($result, 'name');
     // Calling 'git branch' first and then 'git rev-parse' is way faster than
index 8019a2305fd28354f4dbfa44ee013d8132dcbfdd..fa6767f8e003657186ad3d07adb90a64ce0a777b 100644 (file)
@@ -82,7 +82,7 @@ EOTEXT
         continue;
       }
 
-      $rev_id = $branch->getRevisionId();
+      $rev_id = $branch->getRevisionID();
       if ($rev_id) {
         $status = idx($revision_status, $rev_id, 'Unknown Status');
         $branch->setStatus($status);
@@ -153,7 +153,7 @@ EOTEXT
         echo reset($branches)->getFormattedStatus()."\n";
         foreach ($branches as $branch) {
           $name_markdown = $branch->getFormattedName();
-          $subject = $branch->getCommitSubject();
+          $subject = $branch->getCommitDisplayName();
           $name_markdown = str_pad($name_markdown, $longest_name + 4, ' ');
           echo "  $name_markdown $subject\n";
         }
@@ -162,7 +162,7 @@ EOTEXT
       foreach ($this->branches as $branch) {
         $name_markdown = $branch->getFormattedName();
         $status_markdown = $branch->getFormattedStatus();
-        $subject = $branch->getCommitSubject();
+        $subject = $branch->getCommitDisplayName();
         $subject_pad = $longest_status - strlen($branch->getStatus()) + 4;
         $name_markdown =
           str_pad($name_markdown, $longest_name + 4, ' ');