mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-02-02 09:58:23 +01:00
Use 'remote.origin.url' fallback for git < 1.7.5
Summary: 'git ls-remote --get-url' is more correct, but younger and less supported. This commit tempers previous optimism about its availability, improving support for users of older git packages. Test Plan: * Set `git config url.xttps.insteadOf https` rewrite rule. * Ran `arc which` with git 1.7.5 in `$PATH`, saw rewritten configured remote. * Ran `arc which` with git 1.7.4 in `$PATH`, saw configured remote. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D13998
This commit is contained in:
parent
4c3d75401f
commit
c22dfe61ed
1 changed files with 18 additions and 2 deletions
|
@ -51,6 +51,11 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
|
||||||
return 'git';
|
return 'git';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGitVersion() {
|
||||||
|
list($stdout) = $this->execxLocal('--version');
|
||||||
|
return rtrim(str_replace('git version ', '', $stdout));
|
||||||
|
}
|
||||||
|
|
||||||
public function getMetadataPath() {
|
public function getMetadataPath() {
|
||||||
static $path = null;
|
static $path = null;
|
||||||
if ($path === null) {
|
if ($path === null) {
|
||||||
|
@ -516,10 +521,21 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRemoteURI() {
|
public function getRemoteURI() {
|
||||||
list($stdout) = $this->execxLocal('ls-remote --get-url origin');
|
// "git ls-remote --get-url" is the appropriate plumbing to get the remote
|
||||||
|
// URI. "git config remote.origin.url", on the other hand, may not be as
|
||||||
|
// accurate (for example, it does not take into account possible URL
|
||||||
|
// rewriting rules set by the user through "url.<base>.insteadOf"). However,
|
||||||
|
// the --get-url flag requires git 1.7.5.
|
||||||
|
$version = $this->getGitVersion();
|
||||||
|
if (version_compare($version, '1.7.5', '>=')) {
|
||||||
|
list($stdout) = $this->execxLocal('ls-remote --get-url origin');
|
||||||
|
} else {
|
||||||
|
list($stdout) = $this->execxLocal('config remote.origin.url');
|
||||||
|
}
|
||||||
|
|
||||||
$uri = rtrim($stdout);
|
$uri = rtrim($stdout);
|
||||||
if ($uri === 'origin') {
|
// 'origin' is what ls-remote outputs if no origin remote URI exists
|
||||||
|
if (!$uri || $uri === 'origin') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue