diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1f785647..15bb86ce 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -218,6 +218,7 @@ phutil_register_library_map(array( 'ArcanistGitRawCommit' => 'repository/raw/ArcanistGitRawCommit.php', 'ArcanistGitRawCommitTestCase' => 'repository/raw/__tests__/ArcanistGitRawCommitTestCase.php', 'ArcanistGitRepositoryMarkerQuery' => 'repository/marker/ArcanistGitRepositoryMarkerQuery.php', + 'ArcanistGitRepositoryRemoteQuery' => 'repository/remote/ArcanistGitRepositoryRemoteQuery.php', 'ArcanistGitUpstreamPath' => 'repository/api/ArcanistGitUpstreamPath.php', 'ArcanistGitWorkEngine' => 'work/ArcanistGitWorkEngine.php', 'ArcanistGitWorkingCopy' => 'workingcopy/ArcanistGitWorkingCopy.php', @@ -1246,6 +1247,7 @@ phutil_register_library_map(array( 'ArcanistGitRawCommit' => 'Phobject', 'ArcanistGitRawCommitTestCase' => 'PhutilTestCase', 'ArcanistGitRepositoryMarkerQuery' => 'ArcanistRepositoryMarkerQuery', + 'ArcanistGitRepositoryRemoteQuery' => 'ArcanistRepositoryRemoteQuery', 'ArcanistGitUpstreamPath' => 'Phobject', 'ArcanistGitWorkEngine' => 'ArcanistWorkEngine', 'ArcanistGitWorkingCopy' => 'ArcanistWorkingCopy', diff --git a/src/repository/api/ArcanistGitAPI.php b/src/repository/api/ArcanistGitAPI.php index c65257f4..ebd2d1d9 100644 --- a/src/repository/api/ArcanistGitAPI.php +++ b/src/repository/api/ArcanistGitAPI.php @@ -1763,4 +1763,8 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI { return new ArcanistGitRepositoryMarkerQuery(); } + protected function newRemoteRefQueryTemplate() { + return new ArcanistGitRepositoryRemoteQuery(); + } + } diff --git a/src/repository/api/ArcanistMercurialAPI.php b/src/repository/api/ArcanistMercurialAPI.php index e606f6a1..fdb5e1e0 100644 --- a/src/repository/api/ArcanistMercurialAPI.php +++ b/src/repository/api/ArcanistMercurialAPI.php @@ -1014,7 +1014,6 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI { return new ArcanistMercurialRepositoryRemoteQuery(); } - public function getMercurialExtensionArguments() { $path = phutil_get_library_root('arcanist'); $path = dirname($path); diff --git a/src/repository/remote/ArcanistGitRepositoryRemoteQuery.php b/src/repository/remote/ArcanistGitRepositoryRemoteQuery.php new file mode 100644 index 00000000..47b914e9 --- /dev/null +++ b/src/repository/remote/ArcanistGitRepositoryRemoteQuery.php @@ -0,0 +1,63 @@ +getRepositoryAPI(); + + $future = $api->newFuture('remote --verbose'); + list($lines) = $future->resolve(); + + $pattern = + '(^'. + '(?P[^\t]+)'. + '\t'. + '(?P[^\s]+)'. + ' '. + '\((?Pfetch|push)\)'. + '\z'. + ')'; + + $map = array(); + + $lines = phutil_split_lines($lines, false); + foreach ($lines as $line) { + $matches = null; + if (!preg_match($pattern, $line, $matches)) { + throw new Exception( + pht( + 'Failed to match remote pattern against line "%s".', + $line)); + } + + $name = $matches['name']; + $uri = $matches['uri']; + $mode = $matches['mode']; + + $map[$name][$mode] = $uri; + } + + $refs = array(); + foreach ($map as $name => $uris) { + $fetch_uri = idx($uris, 'fetch'); + $push_uri = idx($uris, 'push'); + + $ref = id(new ArcanistRemoteRef()) + ->setRemoteName($name); + + if ($fetch_uri !== null) { + $ref->setFetchURI($fetch_uri); + } + + if ($push_uri !== null) { + $ref->setPushURI($push_uri); + } + + $refs[] = $ref; + } + + return $refs; + } + +}