From 76b54ce0a9af112bac2fb0498d9d44532b46f2d5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 4 Oct 2017 08:22:10 -0700 Subject: [PATCH] Fix parsing of Git branches with common and useful name "0" Summary: See . Oh, PHP! Test Plan: Created a branch named "0", ran `arc diff`. Before: fatal. After: this beautiful revision. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D18678 --- src/repository/api/ArcanistGitAPI.php | 8 ++++++-- src/workflow/ArcanistLandWorkflow.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index a316093e..d1406096 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -497,6 +497,10 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { return null; } + if (!strlen($branch)) { + return null; + } + return $branch; } @@ -509,7 +513,7 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { // Verify this, and strip it. $ref = rtrim($stdout); $branch = $this->getBranchNameFromRef($ref); - if (!$branch) { + if ($branch === null) { throw new Exception( pht('Failed to parse %s output!', 'git symbolic-ref')); } @@ -1015,7 +1019,7 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { list($ref, $hash, $epoch, $tree, $desc, $text) = $fields; $branch = $this->getBranchNameFromRef($ref); - if ($branch) { + if ($branch !== null) { $result[] = array( 'current' => ($branch === $current), 'name' => $branch, diff --git a/src/workflow/ArcanistLandWorkflow.php b/src/workflow/ArcanistLandWorkflow.php index 5f13683a..b3c2b181 100644 --- a/src/workflow/ArcanistLandWorkflow.php +++ b/src/workflow/ArcanistLandWorkflow.php @@ -444,7 +444,7 @@ EOTEXT $branch = $this->getArgument('branch'); if (empty($branch)) { $branch = $this->getBranchOrBookmark(); - if ($branch) { + if ($branch !== null) { $this->branchType = $this->getBranchType($branch); // TODO: This message is misleading when landing a detached head or