1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-19 16:38:51 +02:00

Support inspection of remote refs with "arc inspect remote(...)"

Summary: Ref T13546. Expose remote refs for inspection via "arc inspect". For now, this only works in Mercurial.

Test Plan: Ran "arc inspect remote(default)" in Mercurial, got a ref out.

Maniphest Tasks: T13546

Differential Revision: https://secure.phabricator.com/D21374
This commit is contained in:
epriestley 2020-06-30 11:55:55 -07:00
parent b19985a4bd
commit 89f9eb66a7
4 changed files with 54 additions and 0 deletions

View file

@ -419,6 +419,7 @@ phutil_register_library_map(array(
'ArcanistRefInspector' => 'inspector/ArcanistRefInspector.php',
'ArcanistRefView' => 'ref/ArcanistRefView.php',
'ArcanistRemoteRef' => 'repository/remote/ArcanistRemoteRef.php',
'ArcanistRemoteRefInspector' => 'repository/remote/ArcanistRemoteRefInspector.php',
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
'ArcanistRepositoryAPIMiscTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIMiscTestCase.php',
'ArcanistRepositoryAPIStateTestCase' => 'repository/api/__tests__/ArcanistRepositoryAPIStateTestCase.php',
@ -1449,6 +1450,7 @@ phutil_register_library_map(array(
'ArcanistTerminalStringInterface',
),
'ArcanistRemoteRef' => 'ArcanistRef',
'ArcanistRemoteRefInspector' => 'ArcanistRefInspector',
'ArcanistRepositoryAPI' => 'Phobject',
'ArcanistRepositoryAPIMiscTestCase' => 'PhutilTestCase',
'ArcanistRepositoryAPIStateTestCase' => 'PhutilTestCase',

View file

@ -3,6 +3,17 @@
abstract class ArcanistRefInspector
extends Phobject {
private $workflow;
final public function setWorkflow(ArcanistWorkflow $workflow) {
$this->workflow = $workflow;
return $this;
}
final public function getWorkflow() {
return $this->workflow;
}
abstract public function getInspectFunctionName();
abstract public function newInspectRef(array $argv);

View file

@ -0,0 +1,37 @@
<?php
final class ArcanistRemoteRefInspector
extends ArcanistRefInspector {
public function getInspectFunctionName() {
return 'remote';
}
public function newInspectRef(array $argv) {
if (count($argv) !== 1) {
throw new PhutilArgumentUsageException(
pht(
'Expected exactly one argument to "remote(...)" with a '.
'remote name.'));
}
$remote_name = $argv[0];
$workflow = $this->getWorkflow();
$api = $workflow->getRepositoryAPI();
$ref = $api->newRemoteRefQuery()
->withNames(array($remote_name))
->executeOne();
if (!$ref) {
throw new PhutilArgumentUsageException(
pht(
'This working copy has no remote named "%s".',
$remote_name));
}
return $ref;
}
}

View file

@ -34,6 +34,10 @@ EOTEXT
$inspectors = ArcanistRefInspector::getAllInspectors();
foreach ($inspectors as $inspector) {
$inspector->setWorkflow($this);
}
if (!$objects) {
echo tsprintf(
"%s\n\n",