From: epriestley Date: Wed, 29 Jun 2011 20:21:30 +0000 (-0700) Subject: Fix "arc branch" to work if you are on "(no branch)" add revision IDs X-Git-Tag: conduit-4~295 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4a8e247e668a70c13e65da25ff2c69f1831d3143;p=arcanist.git Fix "arc branch" to work if you are on "(no branch)" add revision IDs 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 --- diff --git a/src/branch/BranchInfo.php b/src/branch/BranchInfo.php index 54beae10..38881c3c 100644 --- a/src/branch/BranchInfo.php +++ b/src/branch/BranchInfo.php @@ -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; } diff --git a/src/repository/api/git/ArcanistGitAPI.php b/src/repository/api/git/ArcanistGitAPI.php index 3c466b0d..e69f7785 100644 --- a/src/repository/api/git/ArcanistGitAPI.php +++ b/src/repository/api/git/ArcanistGitAPI.php @@ -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 diff --git a/src/workflow/branch/ArcanistBranchWorkflow.php b/src/workflow/branch/ArcanistBranchWorkflow.php index 8019a230..fa6767f8 100644 --- a/src/workflow/branch/ArcanistBranchWorkflow.php +++ b/src/workflow/branch/ArcanistBranchWorkflow.php @@ -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, ' ');