From 5ce1d7971746f8bf933d69607219f16de93c9e4f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 2 Apr 2020 08:14:18 -0700 Subject: [PATCH] Fix error behavior of "arc version" when it encounters a library which is not a working copy Summary: Ref T13504. The API has changed here slightly, and if you run "arc version" without "arcanist/" being a Git working copy, it currently fatals in a misleading way. Instead, reach the error properly. Test Plan: Ran "arc version" after moving aside ".git/", got a helpful error message instead of a confusing "call on null" exception. Maniphest Tasks: T13504 Differential Revision: https://secure.phabricator.com/D21050 --- .../workflow/ArcanistVersionWorkflow.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/toolset/workflow/ArcanistVersionWorkflow.php b/src/toolset/workflow/ArcanistVersionWorkflow.php index f004f855..eafca523 100644 --- a/src/toolset/workflow/ArcanistVersionWorkflow.php +++ b/src/toolset/workflow/ArcanistVersionWorkflow.php @@ -48,15 +48,23 @@ EOTEXT ); foreach ($roots as $lib => $root) { - $working_copy = ArcanistWorkingCopy::newFromWorkingDirectory($root); - $repository_api = $working_copy->newRepositoryAPI(); + $is_git = false; - if (!$repository_api instanceof ArcanistGitAPI) { - throw new ArcanistUsageException( + $working_copy = ArcanistWorkingCopy::newFromWorkingDirectory($root); + if ($working_copy) { + $repository_api = $working_copy->newRepositoryAPI(); + if ($repository_api instanceof ArcanistGitAPI) { + $is_git = true; + } + } + + if (!$is_git) { + throw new PhutilArgumentUsageException( pht( - 'Library "%s" is not a Git working copy, so no version '. + 'Library "%s" (at "%s") is not a Git working copy, so no version '. 'information can be provided.', - $lib)); + $lib, + Filesystem::readablePath($root))); } // NOTE: Carefully execute these commands in a way that works on Windows