From 6ecb3fb87d2bce44a2d297a36b5880d8f384157e Mon Sep 17 00:00:00 2001 From: Javier Arteaga Date: Mon, 24 Aug 2015 04:51:03 -0700 Subject: [PATCH] Avoid parsing git "remote show" using "ls-remote" Summary: Ref T5554. This makes git remote URL detection locale-agnostic. The previously suggested `git config remote.origin.url` command does almost the same, but does not support the URL rewriting features in git-config (`url..insteadOf`). This one does, although it has the unintuitive behavior of just printing the passed remote name when the remote does not exist, or even when called outside a git repo. Test Plan: * Switched to non-english locale in which git has a translation. * Ran `arc which` on the Arcanist repo. It could not determine the remote URI. * Applied patch, `arc which` found the URI. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: johnny-bit, Korvin Maniphest Tasks: T5554 Differential Revision: https://secure.phabricator.com/D13983 --- src/repository/api/ArcanistGitAPI.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index b9c6185f..65f5112e 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -501,14 +501,14 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { } public function getRemoteURI() { - list($stdout) = $this->execxLocal('remote show -n origin'); + list($stdout) = $this->execxLocal('ls-remote --get-url origin'); - $matches = null; - if (preg_match('/^\s*Fetch URL: (.*)$/m', $stdout, $matches)) { - return trim($matches[1]); + $uri = rtrim($stdout); + if ($uri === 'origin') { + return null; } - return null; + return $uri; } public function getSourceControlPath() {