1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Examine upstream path instead of assuming "origin"

Summary:
Instead of blindly assuming that "origin" is the repository that
arcanist should communicate with, use the remote that is configured
for the branch in git.

Test Plan:
Used `arc which` with a branch with no upstream, an
origin/master upstream, and an upstream/master upstream -- the last of
which is being used to create and land this diff.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: joshuaspence, Korvin

Differential Revision: https://secure.phabricator.com/D14530
This commit is contained in:
Alex Vandiver 2015-11-19 22:28:02 -08:00
parent b32149495b
commit e730ececbc

View file

@ -521,6 +521,16 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
} }
public function getRemoteURI() { public function getRemoteURI() {
// Determine which remote to examine; default to 'origin'
$remote = 'origin';
$branch = $this->getBranchName();
if ($branch) {
$path = $this->getPathToUpstream($branch);
if ($path->isConnectedToRemote()) {
$remote = $path->getRemoteRemoteName();
}
}
// "git ls-remote --get-url" is the appropriate plumbing to get the remote // "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 // 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 // accurate (for example, it does not take into account possible URL
@ -528,9 +538,9 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
// the --get-url flag requires git 1.7.5. // the --get-url flag requires git 1.7.5.
$version = $this->getGitVersion(); $version = $this->getGitVersion();
if (version_compare($version, '1.7.5', '>=')) { if (version_compare($version, '1.7.5', '>=')) {
list($stdout) = $this->execxLocal('ls-remote --get-url origin'); list($stdout) = $this->execxLocal('ls-remote --get-url %s', $remote);
} else { } else {
list($stdout) = $this->execxLocal('config remote.origin.url'); list($stdout) = $this->execxLocal('config %s', "remote.$remote.url");
} }
$uri = rtrim($stdout); $uri = rtrim($stdout);