]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Examine upstream path instead of assuming "origin"
authorAlex Vandiver <alexmv@dropbox.com>
Fri, 20 Nov 2015 06:28:02 +0000 (22:28 -0800)
committerAlex Vandiver <alexmv@dropbox.com>
Mon, 23 Nov 2015 18:29:20 +0000 (10:29 -0800)
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

src/repository/api/ArcanistGitAPI.php

index d93b808339dfd7e49862dac625ca03c2e2eb9dd1..a3c79312d5d486826833c9828ce19b33c317e8d5 100644 (file)
@@ -521,6 +521,16 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
   }
 
   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
     // 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
@@ -528,9 +538,9 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     // 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');
+      list($stdout) = $this->execxLocal('ls-remote --get-url %s', $remote);
     } else {
-      list($stdout) = $this->execxLocal('config remote.origin.url');
+      list($stdout) = $this->execxLocal('config %s', "remote.$remote.url");
     }
 
     $uri = rtrim($stdout);