1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

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
This commit is contained in:
epriestley 2011-06-29 13:21:30 -07:00
parent ffeeeb8c55
commit 4a8e247e66
3 changed files with 23 additions and 9 deletions

View 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;
}

View 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

View 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, ' ');