diff --git a/src/workflow/ArcanistBrowseWorkflow.php b/src/workflow/ArcanistBrowseWorkflow.php index 3deaf229..42d874fa 100644 --- a/src/workflow/ArcanistBrowseWorkflow.php +++ b/src/workflow/ArcanistBrowseWorkflow.php @@ -1,25 +1,7 @@ array( 'param' => 'branch_name', - 'help' => - "Select branch name to view (on server). Defaults to 'master'." + 'help' => pht( + 'Default branch name to view on server. Defaults to "master".'), ), '*' => 'paths', ); @@ -77,6 +59,13 @@ EOTEXT $project_root = $this->getWorkingCopy()->getProjectRoot(); $in_paths = $this->getArgument('paths'); + if (!$in_paths) { + throw new ArcanistUsageException( + pht( + 'Specify one or more paths to browse. Use the command '. + '"arc browse ." if you want to browse this directory.')); + } + $paths = array(); foreach ($in_paths as $key => $path) { $path = preg_replace('/:([0-9]+)$/', '$\1', $path); @@ -89,15 +78,11 @@ EOTEXT } } - if (!$paths) { - throw new ArcanistUsageException("Specify a path to browse."); - } - $base_uri = $this->getBaseURI(); $browser = $this->getBrowserCommand(); foreach ($paths as $path) { - $ret_code = phutil_passthru("%s %s", $browser, $base_uri . $path); + $ret_code = phutil_passthru('%s %s', $browser, $base_uri.$path); if ($ret_code) { throw new ArcanistUsageException( "It seems we failed to open the browser; perhaps you should try to ". @@ -111,6 +96,14 @@ EOTEXT private function getBaseURI() { $repo_uri = $this->getRepositoryURI(); + if ($repo_uri === null) { + throw new ArcanistUsageException( + pht( + 'arc is unable to determine which repository in Diffusion '. + 'this working copy belongs to. Use "arc which" to understand how '. + 'arc looks for a repository.')); + } + $branch = $this->getArgument('branch', 'master'); return $repo_uri.'browse/'.$branch.'/'; @@ -123,21 +116,25 @@ EOTEXT } if (phutil_is_windows()) { - return "start"; + return 'start'; } - $candidates = array("sensible-browser", "xdg-open", "open"); - // on many Linuxes, "open" exists and is not the right program. + $candidates = array('sensible-browser', 'xdg-open', 'open'); + + // NOTE: The "open" command works well on OS X, but on many Linuxes "open" + // exists and is not a browser. For now, we're just looking for other + // commands first, but we might want to be smarter about selecting "open" + // only on OS X. foreach ($candidates as $cmd) { - list($ret_code) = exec_manual("which %s", $cmd); - if ($ret_code == 0) { + if (Filesystem::binaryExists($cmd)) { return $cmd; } } throw new ArcanistUsageException( - "Could not find a browser to run; Try setting the 'browser' option " . - "using arc set-config."); + pht( + "Unable to find a browser command to run. Set 'browser' in your ". + "arc config to specify one.")); } }