2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-10 00:22:25 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Implements a runnable command, like "arc diff" or "arc help".
|
|
|
|
*
|
2011-07-14 00:03:40 +02:00
|
|
|
* = Managing Conduit =
|
|
|
|
*
|
|
|
|
* Workflows have the builtin ability to open a Conduit connection to a
|
|
|
|
* Phabricator installation, so methods can be invoked over the API. Workflows
|
|
|
|
* may either not need this (e.g., "help"), or may need a Conduit but not
|
|
|
|
* authentication (e.g., calling only public APIs), or may need a Conduit and
|
|
|
|
* authentication (e.g., "arc diff").
|
|
|
|
*
|
|
|
|
* To specify that you need an //unauthenticated// conduit, override
|
|
|
|
* @{method:requiresConduit} to return ##true##. To specify that you need an
|
|
|
|
* //authenticated// conduit, override @{method:requiresAuthentication} to
|
|
|
|
* return ##true##. You can also manually invoke @{method:establishConduit}
|
|
|
|
* and/or @{method:authenticateConduit} later in a workflow to upgrade it.
|
|
|
|
* Once a conduit is open, you can access the client by calling
|
|
|
|
* @{method:getConduit}, which allows you to invoke methods. You can get
|
2011-07-15 21:44:03 +02:00
|
|
|
* verified information about the user identity by calling @{method:getUserPHID}
|
2011-07-14 00:03:40 +02:00
|
|
|
* or @{method:getUserName} after authentication occurs.
|
|
|
|
*
|
2012-02-21 21:35:39 +01:00
|
|
|
* = Scratch Files =
|
|
|
|
*
|
|
|
|
* Arcanist workflows can read and write 'scratch files', which are temporary
|
|
|
|
* files stored in the project that persist across commands. They can be useful
|
|
|
|
* if you want to save some state, or keep a copy of a long message the user
|
|
|
|
* entered in something goes wrong..
|
|
|
|
*
|
|
|
|
*
|
2011-07-14 00:03:40 +02:00
|
|
|
* @task conduit Conduit
|
2012-02-21 21:35:39 +01:00
|
|
|
* @task scratch Scratch Files
|
2011-02-19 20:36:08 +01:00
|
|
|
* @group workflow
|
2012-01-31 21:07:05 +01:00
|
|
|
* @stable
|
2011-02-19 20:36:08 +01:00
|
|
|
*/
|
2012-01-31 21:07:05 +01:00
|
|
|
abstract class ArcanistBaseWorkflow {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
private $conduit;
|
2011-07-14 00:03:40 +02:00
|
|
|
private $conduitURI;
|
|
|
|
private $conduitCredentials;
|
|
|
|
private $conduitAuthenticated;
|
2012-05-22 01:45:03 +02:00
|
|
|
private $forcedConduitVersion;
|
2012-06-03 17:31:49 +02:00
|
|
|
private $conduitTimeout;
|
2011-07-14 00:03:40 +02:00
|
|
|
|
2011-07-15 21:44:03 +02:00
|
|
|
private $userPHID;
|
2011-01-10 00:22:25 +01:00
|
|
|
private $userName;
|
|
|
|
private $repositoryAPI;
|
|
|
|
private $workingCopy;
|
|
|
|
private $arguments;
|
|
|
|
private $command;
|
|
|
|
|
2012-03-14 15:08:06 +01:00
|
|
|
private $repositoryEncoding;
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
private $arcanistConfiguration;
|
|
|
|
private $parentWorkflow;
|
2011-06-14 21:18:40 +02:00
|
|
|
private $workingDirectory;
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
private $changeCache = array();
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:03:40 +02:00
|
|
|
|
|
|
|
/* -( Conduit )------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the URI which the workflow will open a conduit connection to when
|
|
|
|
* @{method:establishConduit} is called. Arcanist makes an effort to set
|
|
|
|
* this by default for all workflows (by reading ##.arcconfig## and/or the
|
|
|
|
* value of ##--conduit-uri##) even if they don't need Conduit, so a workflow
|
|
|
|
* can generally upgrade into a conduit workflow later by just calling
|
|
|
|
* @{method:establishConduit}.
|
|
|
|
*
|
|
|
|
* You generally should not need to call this method unless you are
|
|
|
|
* specifically overriding the default URI. It is normally sufficient to
|
|
|
|
* just invoke @{method:establishConduit}.
|
|
|
|
*
|
|
|
|
* NOTE: You can not call this after a conduit has been established.
|
|
|
|
*
|
|
|
|
* @param string The URI to open a conduit to when @{method:establishConduit}
|
|
|
|
* is called.
|
|
|
|
* @return this
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function setConduitURI($conduit_uri) {
|
|
|
|
if ($this->conduit) {
|
|
|
|
throw new Exception(
|
|
|
|
"You can not change the Conduit URI after a conduit is already open.");
|
|
|
|
}
|
|
|
|
$this->conduitURI = $conduit_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-01-24 00:31:56 +01:00
|
|
|
/**
|
|
|
|
* Returns the URI the conduit connection within the workflow uses.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function getConduitURI() {
|
|
|
|
return $this->conduitURI;
|
|
|
|
}
|
2011-07-14 00:03:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a conduit channel to the server which was previously configured by
|
|
|
|
* calling @{method:setConduitURI}. Arcanist will do this automatically if
|
|
|
|
* the workflow returns ##true## from @{method:requiresConduit}, or you can
|
|
|
|
* later upgrade a workflow and build a conduit by invoking it manually.
|
|
|
|
*
|
|
|
|
* You must establish a conduit before you can make conduit calls.
|
|
|
|
*
|
|
|
|
* NOTE: You must call @{method:setConduitURI} before you can call this
|
|
|
|
* method.
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function establishConduit() {
|
|
|
|
if ($this->conduit) {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->conduitURI) {
|
|
|
|
throw new Exception(
|
|
|
|
"You must specify a Conduit URI with setConduitURI() before you can ".
|
|
|
|
"establish a conduit.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->conduit = new ConduitClient($this->conduitURI);
|
|
|
|
|
2012-06-03 17:31:49 +02:00
|
|
|
if ($this->conduitTimeout) {
|
|
|
|
$this->conduit->setTimeout($this->conduitTimeout);
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:03:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set credentials which will be used to authenticate against Conduit. These
|
|
|
|
* credentials can then be used to establish an authenticated connection to
|
|
|
|
* conduit by calling @{method:authenticateConduit}. Arcanist sets some
|
|
|
|
* defaults for all workflows regardless of whether or not they return true
|
|
|
|
* from @{method:requireAuthentication}, based on the ##~/.arcrc## and
|
|
|
|
* ##.arcconf## files if they are present. Thus, you can generally upgrade a
|
|
|
|
* workflow which does not require authentication into an authenticated
|
|
|
|
* workflow by later invoking @{method:requireAuthentication}. You should not
|
|
|
|
* normally need to call this method unless you are specifically overriding
|
|
|
|
* the defaults.
|
|
|
|
*
|
|
|
|
* NOTE: You can not call this method after calling
|
|
|
|
* @{method:authenticateConduit}.
|
|
|
|
*
|
|
|
|
* @param dict A credential dictionary, see @{method:authenticateConduit}.
|
|
|
|
* @return this
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function setConduitCredentials(array $credentials) {
|
2012-02-20 00:24:03 +01:00
|
|
|
if ($this->isConduitAuthenticated()) {
|
2011-07-14 00:03:40 +02:00
|
|
|
throw new Exception(
|
|
|
|
"You may not set new credentials after authenticating conduit.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->conduitCredentials = $credentials;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-06-03 17:31:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Force arc to identify with a specific Conduit version during the
|
|
|
|
* protocol handshake. This is primarily useful for development (especially
|
|
|
|
* for sending diffs which bump the client Conduit version), since the client
|
|
|
|
* still actually speaks the builtin version of the protocol.
|
|
|
|
*
|
|
|
|
* Controlled by the --conduit-version flag.
|
|
|
|
*
|
|
|
|
* @param int Version the client should pretend to be.
|
|
|
|
* @return this
|
|
|
|
* @task conduit
|
|
|
|
*/
|
2012-05-22 01:45:03 +02:00
|
|
|
public function forceConduitVersion($version) {
|
|
|
|
$this->forcedConduitVersion = $version;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-06-03 17:31:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the protocol version the client should identify with.
|
|
|
|
*
|
|
|
|
* @return int Version the client should claim to be.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
2012-05-22 01:45:03 +02:00
|
|
|
public function getConduitVersion() {
|
|
|
|
return nonempty($this->forcedConduitVersion, 5);
|
|
|
|
}
|
2011-07-14 00:03:40 +02:00
|
|
|
|
2012-06-03 17:31:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the default timeout for Conduit.
|
|
|
|
*
|
|
|
|
* Controlled by the --conduit-timeout flag.
|
|
|
|
*
|
|
|
|
* @param float Timeout, in seconds.
|
|
|
|
* @return this
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
public function setConduitTimeout($timeout) {
|
|
|
|
$this->conduitTimeout = $timeout;
|
|
|
|
if ($this->conduit) {
|
|
|
|
$this->conduit->setConduitTimeout($timeout);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-14 00:03:40 +02:00
|
|
|
/**
|
|
|
|
* Open and authenticate a conduit connection to a Phabricator server using
|
|
|
|
* provided credentials. Normally, Arcanist does this for you automatically
|
|
|
|
* when you return true from @{method:requiresAuthentication}, but you can
|
|
|
|
* also upgrade an existing workflow to one with an authenticated conduit
|
|
|
|
* by invoking this method manually.
|
|
|
|
*
|
|
|
|
* You must authenticate the conduit before you can make authenticated conduit
|
|
|
|
* calls (almost all calls require authentication).
|
|
|
|
*
|
|
|
|
* This method uses credentials provided via @{method:setConduitCredentials}
|
|
|
|
* to authenticate to the server:
|
|
|
|
*
|
|
|
|
* - ##user## (required) The username to authenticate with.
|
|
|
|
* - ##certificate## (required) The Conduit certificate to use.
|
|
|
|
* - ##description## (optional) Description of the invoking command.
|
|
|
|
*
|
2011-07-15 21:44:03 +02:00
|
|
|
* Successful authentication allows you to call @{method:getUserPHID} and
|
2011-07-14 00:03:40 +02:00
|
|
|
* @{method:getUserName}, as well as use the client you access with
|
|
|
|
* @{method:getConduit} to make authenticated calls.
|
|
|
|
*
|
|
|
|
* NOTE: You must call @{method:setConduitURI} and
|
|
|
|
* @{method:setConduitCredentials} before you invoke this method.
|
|
|
|
*
|
|
|
|
* @return this
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function authenticateConduit() {
|
2012-02-20 00:24:03 +01:00
|
|
|
if ($this->isConduitAuthenticated()) {
|
2011-07-14 00:03:40 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->establishConduit();
|
|
|
|
|
|
|
|
$credentials = $this->conduitCredentials;
|
|
|
|
if (!$credentials) {
|
|
|
|
throw new Exception(
|
|
|
|
"Set conduit credentials with setConduitCredentials() before ".
|
|
|
|
"authenticating conduit!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($credentials['user']) || empty($credentials['certificate'])) {
|
|
|
|
throw new Exception(
|
|
|
|
"Credentials must include a 'user' and a 'certificate'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$description = idx($credentials, 'description', '');
|
|
|
|
$user = $credentials['user'];
|
|
|
|
$certificate = $credentials['certificate'];
|
|
|
|
|
|
|
|
try {
|
|
|
|
$connection = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'conduit.connect',
|
|
|
|
array(
|
|
|
|
'client' => 'arc',
|
2012-05-22 01:45:03 +02:00
|
|
|
'clientVersion' => $this->getConduitVersion(),
|
2011-07-14 00:03:40 +02:00
|
|
|
'clientDescription' => php_uname('n').':'.$description,
|
|
|
|
'user' => $user,
|
|
|
|
'certificate' => $certificate,
|
|
|
|
'host' => $this->conduitURI,
|
|
|
|
));
|
|
|
|
} catch (ConduitClientException $ex) {
|
|
|
|
if ($ex->getErrorCode() == 'ERR-NO-CERTIFICATE' ||
|
|
|
|
$ex->getErrorCode() == 'ERR-INVALID-USER') {
|
2011-08-07 23:54:32 +02:00
|
|
|
$conduit_uri = $this->conduitURI;
|
2011-07-14 00:03:40 +02:00
|
|
|
$message =
|
|
|
|
"\n".
|
|
|
|
phutil_console_format(
|
|
|
|
"YOU NEED TO __INSTALL A CERTIFICATE__ TO LOGIN TO PHABRICATOR").
|
|
|
|
"\n\n".
|
|
|
|
phutil_console_format(
|
|
|
|
" To do this, run: **arc install-certificate**").
|
|
|
|
"\n\n".
|
|
|
|
"The server '{$conduit_uri}' rejected your request:".
|
|
|
|
"\n".
|
|
|
|
$ex->getMessage();
|
|
|
|
throw new ArcanistUsageException($message);
|
2012-05-09 19:01:31 +02:00
|
|
|
} else if ($ex->getErrorCode() == 'NEW-ARC-VERSION') {
|
|
|
|
|
|
|
|
// Cleverly disguise this as being AWESOME!!!
|
|
|
|
|
|
|
|
echo phutil_console_format("**New Version Available!**\n\n");
|
|
|
|
echo phutil_console_wrap($ex->getMessage());
|
|
|
|
echo "\n\n";
|
|
|
|
echo "In most cases, arc can be upgraded automatically.\n";
|
|
|
|
|
|
|
|
$ok = phutil_console_confirm(
|
|
|
|
"Upgrade arc now?",
|
|
|
|
$default_no = false);
|
|
|
|
if (!$ok) {
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
$root = dirname(phutil_get_library_root('arcanist'));
|
|
|
|
|
|
|
|
chdir($root);
|
|
|
|
$err = phutil_passthru('%s upgrade', $root.'/bin/arc');
|
|
|
|
if (!$err) {
|
|
|
|
echo "\nTry running your arc command again.\n";
|
|
|
|
}
|
|
|
|
exit(1);
|
2011-07-14 00:03:40 +02:00
|
|
|
} else {
|
|
|
|
throw $ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->userName = $user;
|
2011-07-15 21:44:03 +02:00
|
|
|
$this->userPHID = $connection['userPHID'];
|
2011-07-14 00:03:40 +02:00
|
|
|
|
|
|
|
$this->conduitAuthenticated = true;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-02-20 00:24:03 +01:00
|
|
|
/**
|
|
|
|
* @return bool True if conduit is authenticated, false otherwise.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final protected function isConduitAuthenticated() {
|
2012-06-03 17:31:49 +02:00
|
|
|
return (bool)$this->conduitAuthenticated;
|
2012-02-20 00:24:03 +01:00
|
|
|
}
|
|
|
|
|
2011-07-14 00:03:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override this to return true if your workflow requires a conduit channel.
|
|
|
|
* Arc will build the channel for you before your workflow executes. This
|
|
|
|
* implies that you only need an unauthenticated channel; if you need
|
|
|
|
* authentication, override @{method:requiresAuthentication}.
|
|
|
|
*
|
|
|
|
* @return bool True if arc should build a conduit channel before running
|
|
|
|
* the workflow.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
public function requiresConduit() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override this to return true if your workflow requires an authenticated
|
|
|
|
* conduit channel. This implies that it requires a conduit. Arc will build
|
|
|
|
* and authenticate the channel for you before the workflow executes.
|
|
|
|
*
|
|
|
|
* @return bool True if arc should build an authenticated conduit channel
|
|
|
|
* before running the workflow.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the PHID for the user once they've authenticated via Conduit.
|
|
|
|
*
|
|
|
|
* @return phid Authenticated user PHID.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
2011-07-15 21:44:03 +02:00
|
|
|
final public function getUserPHID() {
|
|
|
|
if (!$this->userPHID) {
|
2011-07-14 00:03:40 +02:00
|
|
|
$workflow = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"This workflow ('{$workflow}') requires authentication, override ".
|
|
|
|
"requiresAuthentication() to return true.");
|
|
|
|
}
|
2011-07-15 21:44:03 +02:00
|
|
|
return $this->userPHID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deprecated. See @{method:getUserPHID}.
|
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
final public function getUserGUID() {
|
|
|
|
phutil_deprecated(
|
|
|
|
'ArcanistBaseWorkflow::getUserGUID',
|
|
|
|
'This method has been renamed to getUserPHID().');
|
|
|
|
return $this->getUserPHID();
|
2011-07-14 00:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the username for the user once they've authenticated via Conduit.
|
|
|
|
*
|
|
|
|
* @return string Authenticated username.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function getUserName() {
|
|
|
|
return $this->userName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the established @{class@libphutil:ConduitClient} in order to make
|
|
|
|
* Conduit method calls. Before the client is available it must be connected,
|
|
|
|
* either implicitly by making @{method:requireConduit} or
|
|
|
|
* @{method:requireAuthentication} return true, or explicitly by calling
|
|
|
|
* @{method:establishConduit} or @{method:authenticateConduit}.
|
|
|
|
*
|
|
|
|
* @return @{class@libphutil:ConduitClient} Live conduit client.
|
|
|
|
* @task conduit
|
|
|
|
*/
|
|
|
|
final public function getConduit() {
|
|
|
|
if (!$this->conduit) {
|
|
|
|
$workflow = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"This workflow ('{$workflow}') requires a Conduit, override ".
|
|
|
|
"requiresConduit() to return true.");
|
|
|
|
}
|
|
|
|
return $this->conduit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function setArcanistConfiguration($arcanist_configuration) {
|
|
|
|
$this->arcanistConfiguration = $arcanist_configuration;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArcanistConfiguration() {
|
|
|
|
return $this->arcanistConfiguration;
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
|
|
|
return get_class($this).": Undocumented";
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function getCommandHelp() {
|
|
|
|
return get_class($this).": Undocumented";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-14 01:02:29 +02:00
|
|
|
public function desiresWorkingCopy() {
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-14 01:02:29 +02:00
|
|
|
public function desiresRepositoryAPI() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function setCommand($command) {
|
|
|
|
$this->command = $command;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommand() {
|
|
|
|
return $this->command;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:18:40 +02:00
|
|
|
public function setWorkingDirectory($working_directory) {
|
|
|
|
$this->workingDirectory = $working_directory;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getWorkingDirectory() {
|
|
|
|
return $this->workingDirectory;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
private function setParentWorkflow($parent_workflow) {
|
|
|
|
$this->parentWorkflow = $parent_workflow;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getParentWorkflow() {
|
|
|
|
return $this->parentWorkflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildChildWorkflow($command, array $argv) {
|
|
|
|
$arc_config = $this->getArcanistConfiguration();
|
|
|
|
$workflow = $arc_config->buildWorkflow($command);
|
|
|
|
$workflow->setParentWorkflow($this);
|
|
|
|
$workflow->setCommand($command);
|
|
|
|
|
|
|
|
if ($this->repositoryAPI) {
|
|
|
|
$workflow->setRepositoryAPI($this->repositoryAPI);
|
|
|
|
}
|
|
|
|
|
2011-07-15 21:44:03 +02:00
|
|
|
if ($this->userPHID) {
|
|
|
|
$workflow->userPHID = $this->getUserPHID();
|
2011-07-14 00:03:40 +02:00
|
|
|
$workflow->userName = $this->getUserName();
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->conduit) {
|
2011-07-14 00:03:40 +02:00
|
|
|
$workflow->conduit = $this->conduit;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->workingCopy) {
|
|
|
|
$workflow->setWorkingCopy($this->workingCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
$workflow->setArcanistConfiguration($arc_config);
|
|
|
|
|
|
|
|
$workflow->parseArguments(array_values($argv));
|
|
|
|
|
|
|
|
return $workflow;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArgument($key, $default = null) {
|
2012-06-08 02:02:56 +02:00
|
|
|
return idx($this->arguments, $key, $default);
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
final public function getCompleteArgumentSpecification() {
|
|
|
|
$spec = $this->getArguments();
|
|
|
|
$arc_config = $this->getArcanistConfiguration();
|
|
|
|
$command = $this->getCommand();
|
|
|
|
$spec += $arc_config->getCustomArgumentsForCommand($command);
|
|
|
|
return $spec;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function parseArguments(array $args) {
|
|
|
|
|
|
|
|
$spec = $this->getCompleteArgumentSpecification();
|
|
|
|
|
|
|
|
$dict = array();
|
|
|
|
|
|
|
|
$more_key = null;
|
|
|
|
if (!empty($spec['*'])) {
|
|
|
|
$more_key = $spec['*'];
|
|
|
|
unset($spec['*']);
|
|
|
|
$dict[$more_key] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$short_to_long_map = array();
|
|
|
|
foreach ($spec as $long => $options) {
|
|
|
|
if (!empty($options['short'])) {
|
|
|
|
$short_to_long_map[$options['short']] = $long;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 02:02:56 +02:00
|
|
|
foreach ($spec as $long => $options) {
|
|
|
|
if (!empty($options['repeat'])) {
|
|
|
|
$dict[$long] = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$more = array();
|
|
|
|
for ($ii = 0; $ii < count($args); $ii++) {
|
|
|
|
$arg = $args[$ii];
|
|
|
|
$arg_name = null;
|
|
|
|
$arg_key = null;
|
|
|
|
if ($arg == '--') {
|
|
|
|
$more = array_merge(
|
|
|
|
$more,
|
|
|
|
array_slice($args, $ii + 1));
|
|
|
|
break;
|
|
|
|
} else if (!strncmp($arg, '--', 2)) {
|
|
|
|
$arg_key = substr($arg, 2);
|
|
|
|
if (!array_key_exists($arg_key, $spec)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Unknown argument '{$arg_key}'. Try 'arc help'.");
|
|
|
|
}
|
|
|
|
} else if (!strncmp($arg, '-', 1)) {
|
|
|
|
$arg_key = substr($arg, 1);
|
|
|
|
if (empty($short_to_long_map[$arg_key])) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Unknown argument '{$arg_key}'. Try 'arc help'.");
|
|
|
|
}
|
|
|
|
$arg_key = $short_to_long_map[$arg_key];
|
|
|
|
} else {
|
|
|
|
$more[] = $arg;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$options = $spec[$arg_key];
|
|
|
|
if (empty($options['param'])) {
|
|
|
|
$dict[$arg_key] = true;
|
|
|
|
} else {
|
|
|
|
if ($ii == count($args) - 1) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Option '{$arg}' requires a parameter.");
|
|
|
|
}
|
2012-06-08 02:02:56 +02:00
|
|
|
if (!empty($options['repeat'])) {
|
|
|
|
$dict[$arg_key][] = $args[$ii + 1];
|
|
|
|
} else {
|
|
|
|
$dict[$arg_key] = $args[$ii + 1];
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
$ii++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($more) {
|
|
|
|
if ($more_key) {
|
|
|
|
$dict[$more_key] = $more;
|
|
|
|
} else {
|
|
|
|
$example = reset($more);
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Unrecognized argument '{$example}'. Try 'arc help'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($dict as $key => $value) {
|
|
|
|
if (empty($spec[$key]['conflicts'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($spec[$key]['conflicts'] as $conflict => $more) {
|
|
|
|
if (isset($dict[$conflict])) {
|
|
|
|
if ($more) {
|
|
|
|
$more = ': '.$more;
|
|
|
|
} else {
|
|
|
|
$more = '.';
|
|
|
|
}
|
|
|
|
// TODO: We'll always display these as long-form, when the user might
|
|
|
|
// have typed them as short form.
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Arguments '--{$key}' and '--{$conflict}' are mutually exclusive".
|
|
|
|
$more);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->arguments = $dict;
|
|
|
|
|
|
|
|
$this->didParseArguments();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function didParseArguments() {
|
|
|
|
// Override this to customize workflow argument behavior.
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getWorkingCopy() {
|
|
|
|
if (!$this->workingCopy) {
|
|
|
|
$workflow = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"This workflow ('{$workflow}') requires a working copy, override ".
|
|
|
|
"requiresWorkingCopy() to return true.");
|
|
|
|
}
|
|
|
|
return $this->workingCopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setWorkingCopy(
|
|
|
|
ArcanistWorkingCopyIdentity $working_copy) {
|
|
|
|
$this->workingCopy = $working_copy;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setRepositoryAPI($api) {
|
|
|
|
$this->repositoryAPI = $api;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRepositoryAPI() {
|
|
|
|
if (!$this->repositoryAPI) {
|
|
|
|
$workflow = get_class($this);
|
|
|
|
throw new Exception(
|
|
|
|
"This workflow ('{$workflow}') requires a Repository API, override ".
|
|
|
|
"requiresRepositoryAPI() to return true.");
|
|
|
|
}
|
|
|
|
return $this->repositoryAPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldRequireCleanUntrackedFiles() {
|
|
|
|
return empty($this->arguments['allow-untracked']);
|
|
|
|
}
|
|
|
|
|
2011-09-09 02:36:20 +02:00
|
|
|
public function requireCleanWorkingCopy() {
|
2011-01-10 00:22:25 +01:00
|
|
|
$api = $this->getRepositoryAPI();
|
|
|
|
|
2011-03-13 03:16:15 +01:00
|
|
|
$working_copy_desc = phutil_console_format(
|
|
|
|
" Working copy: __%s__\n\n",
|
|
|
|
$api->getPath());
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$untracked = $api->getUntrackedChanges();
|
|
|
|
if ($this->shouldRequireCleanUntrackedFiles()) {
|
2012-02-21 21:35:39 +01:00
|
|
|
|
|
|
|
// Exempt ".arc/" scratch files from this warning so that things work
|
|
|
|
// a little more smoothly if no one has gotten around to adding .arc to
|
|
|
|
// the ignore list.
|
|
|
|
foreach ($untracked as $key => $path) {
|
|
|
|
if (preg_match('@\.arc/@', $path)) {
|
|
|
|
unset($untracked[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
if (!empty($untracked)) {
|
2011-03-13 03:16:15 +01:00
|
|
|
echo "You have untracked files in this working copy.\n\n".
|
|
|
|
$working_copy_desc.
|
|
|
|
" Untracked files in working copy:\n".
|
2011-03-13 02:57:35 +01:00
|
|
|
" ".implode("\n ", $untracked)."\n\n";
|
|
|
|
|
|
|
|
if ($api instanceof ArcanistGitAPI) {
|
|
|
|
echo phutil_console_wrap(
|
2011-03-13 03:16:15 +01:00
|
|
|
"Since you don't have '.gitignore' rules for these files and have ".
|
|
|
|
"not listed them in '.git/info/exclude', you may have forgotten ".
|
2011-03-13 02:57:35 +01:00
|
|
|
"to 'git add' them to your commit.");
|
|
|
|
} else if ($api instanceof ArcanistSubversionAPI) {
|
|
|
|
echo phutil_console_wrap(
|
2011-03-13 03:16:15 +01:00
|
|
|
"Since you don't have 'svn:ignore' rules for these files, you may ".
|
2011-03-13 02:57:35 +01:00
|
|
|
"have forgotten to 'svn add' them.");
|
2011-08-10 03:54:10 +02:00
|
|
|
} else if ($api instanceof ArcanistMercurialAPI) {
|
|
|
|
echo phutil_console_wrap(
|
|
|
|
"Since you don't have '.hgignore' rules for these files, you ".
|
|
|
|
"may have forgotten to 'hg add' them to your commit.");
|
2011-03-13 02:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$prompt = "Do you want to continue without adding these files?";
|
|
|
|
if (!phutil_console_confirm($prompt, $default_no = false)) {
|
|
|
|
throw new ArcanistUserAbortException();
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-13 02:57:35 +01:00
|
|
|
$incomplete = $api->getIncompleteChanges();
|
|
|
|
if ($incomplete) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"You have incompletely checked out directories in this working copy. ".
|
2011-03-13 03:16:15 +01:00
|
|
|
"Fix them before proceeding.\n\n".
|
|
|
|
$working_copy_desc.
|
|
|
|
" Incomplete directories in working copy:\n".
|
2011-03-13 02:57:35 +01:00
|
|
|
" ".implode("\n ", $incomplete)."\n\n".
|
|
|
|
"You can fix these paths by running 'svn update' on them.");
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2011-03-13 03:16:15 +01:00
|
|
|
$conflicts = $api->getMergeConflicts();
|
|
|
|
if ($conflicts) {
|
2011-01-10 00:22:25 +01:00
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"You have merge conflicts in this working copy. Resolve merge ".
|
2011-03-13 03:16:15 +01:00
|
|
|
"conflicts before proceeding.\n\n".
|
|
|
|
$working_copy_desc.
|
|
|
|
" Conflicts in working copy:\n".
|
|
|
|
" ".implode("\n ", $conflicts)."\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2011-03-13 03:16:15 +01:00
|
|
|
$unstaged = $api->getUnstagedChanges();
|
|
|
|
if ($unstaged) {
|
2011-01-10 00:22:25 +01:00
|
|
|
throw new ArcanistUsageException(
|
2011-03-13 03:16:15 +01:00
|
|
|
"You have unstaged changes in this working copy. Stage and commit (or ".
|
|
|
|
"revert) them before proceeding.\n\n".
|
|
|
|
$working_copy_desc.
|
|
|
|
" Unstaged changes in working copy:\n".
|
|
|
|
" ".implode("\n ", $unstaged)."\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2011-03-13 03:16:15 +01:00
|
|
|
$uncommitted = $api->getUncommittedChanges();
|
|
|
|
if ($uncommitted) {
|
2012-03-20 03:17:10 +01:00
|
|
|
throw new ArcanistUncommittedChangesException(
|
|
|
|
"You have uncommitted changes in this working copy. Commit (or ".
|
|
|
|
"revert) them before proceeding.\n\n".
|
2011-03-13 03:16:15 +01:00
|
|
|
$working_copy_desc.
|
|
|
|
" Uncommitted changes in working copy\n".
|
|
|
|
" ".implode("\n ", $uncommitted)."\n");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function loadDiffBundleFromConduit(
|
|
|
|
ConduitClient $conduit,
|
|
|
|
$diff_id) {
|
|
|
|
|
|
|
|
return $this->loadBundleFromConduit(
|
|
|
|
$conduit,
|
|
|
|
array(
|
|
|
|
'diff_id' => $diff_id,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadRevisionBundleFromConduit(
|
|
|
|
ConduitClient $conduit,
|
|
|
|
$revision_id) {
|
|
|
|
|
|
|
|
return $this->loadBundleFromConduit(
|
|
|
|
$conduit,
|
|
|
|
array(
|
|
|
|
'revision_id' => $revision_id,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function loadBundleFromConduit(
|
|
|
|
ConduitClient $conduit,
|
|
|
|
$params) {
|
|
|
|
|
|
|
|
$future = $conduit->callMethod('differential.getdiff', $params);
|
|
|
|
$diff = $future->resolve();
|
|
|
|
|
|
|
|
$changes = array();
|
|
|
|
foreach ($diff['changes'] as $changedict) {
|
|
|
|
$changes[] = ArcanistDiffChange::newFromDictionary($changedict);
|
|
|
|
}
|
|
|
|
$bundle = ArcanistBundle::newFromChanges($changes);
|
2011-05-21 16:52:49 +02:00
|
|
|
$bundle->setConduit($conduit);
|
2011-11-30 07:27:40 +01:00
|
|
|
$bundle->setProjectID($diff['projectName']);
|
2011-12-03 01:21:14 +01:00
|
|
|
$bundle->setBaseRevision($diff['sourceControlBaseRevision']);
|
2012-01-18 00:47:00 +01:00
|
|
|
$bundle->setRevisionID($diff['revisionID']);
|
2011-01-10 00:22:25 +01:00
|
|
|
return $bundle;
|
|
|
|
}
|
|
|
|
|
2011-11-03 21:42:19 +01:00
|
|
|
/**
|
|
|
|
* Return a list of lines changed by the current diff, or ##null## if the
|
|
|
|
* change list is meaningless (for example, because the path is a directory
|
|
|
|
* or binary file).
|
|
|
|
*
|
|
|
|
* @param string Path within the repository.
|
|
|
|
* @param string Change selection mode (see ArcanistDiffHunk).
|
|
|
|
* @return list|null List of changed line numbers, or null to indicate that
|
|
|
|
* the path is not a line-oriented text file.
|
|
|
|
*/
|
2011-01-10 00:22:25 +01:00
|
|
|
protected function getChangedLines($path, $mode) {
|
2011-11-03 21:42:19 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
$full_path = $repository_api->getPath($path);
|
|
|
|
if (is_dir($full_path)) {
|
|
|
|
return null;
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2012-03-14 07:42:05 +01:00
|
|
|
if (!file_exists($full_path)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$change = $this->getChange($path);
|
2011-11-03 21:42:19 +01:00
|
|
|
|
|
|
|
if ($change->getFileType() !== ArcanistDiffChangeType::FILE_TEXT) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$lines = $change->getChangedLines($mode);
|
|
|
|
return array_keys($lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getChange($path) {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
if ($repository_api instanceof ArcanistSubversionAPI) {
|
2011-09-15 03:44:54 +02:00
|
|
|
// NOTE: In SVN, we don't currently support a "get all local changes"
|
|
|
|
// operation, so special case it.
|
2011-01-10 00:22:25 +01:00
|
|
|
if (empty($this->changeCache[$path])) {
|
|
|
|
$diff = $repository_api->getRawDiffText($path);
|
|
|
|
$parser = new ArcanistDiffParser();
|
|
|
|
$changes = $parser->parseDiff($diff);
|
|
|
|
if (count($changes) != 1) {
|
|
|
|
throw new Exception("Expected exactly one change.");
|
|
|
|
}
|
|
|
|
$this->changeCache[$path] = reset($changes);
|
|
|
|
}
|
2011-09-15 03:44:54 +02:00
|
|
|
} else if ($repository_api->supportsRelativeLocalCommits()) {
|
2011-01-10 00:22:25 +01:00
|
|
|
if (empty($this->changeCache)) {
|
2011-09-15 03:44:54 +02:00
|
|
|
$changes = $repository_api->getAllLocalChanges();
|
2011-01-10 00:22:25 +01:00
|
|
|
foreach ($changes as $change) {
|
|
|
|
$this->changeCache[$change->getCurrentPath()] = $change;
|
|
|
|
}
|
|
|
|
}
|
2011-09-15 03:44:54 +02:00
|
|
|
} else {
|
|
|
|
throw new Exception("Missing VCS support.");
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->changeCache[$path])) {
|
2011-01-10 05:40:13 +01:00
|
|
|
if ($repository_api instanceof ArcanistGitAPI) {
|
|
|
|
// This can legitimately occur under git if you make a change, "git
|
|
|
|
// commit" it, and then revert the change in the working copy and run
|
|
|
|
// "arc lint".
|
|
|
|
$change = new ArcanistDiffChange();
|
|
|
|
$change->setCurrentPath($path);
|
|
|
|
return $change;
|
|
|
|
} else {
|
|
|
|
throw new Exception(
|
|
|
|
"Trying to get change for unchanged path '{$path}'!");
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->changeCache[$path];
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function willRunWorkflow() {
|
|
|
|
$spec = $this->getCompleteArgumentSpecification();
|
|
|
|
foreach ($this->arguments as $arg => $value) {
|
|
|
|
if (empty($spec[$arg])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$options = $spec[$arg];
|
|
|
|
if (!empty($options['supports'])) {
|
|
|
|
$system_name = $this->getRepositoryAPI()->getSourceControlSystemName();
|
|
|
|
if (!in_array($system_name, $options['supports'])) {
|
|
|
|
$extended_info = null;
|
|
|
|
if (!empty($options['nosupport'][$system_name])) {
|
|
|
|
$extended_info = ' '.$options['nosupport'][$system_name];
|
|
|
|
}
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Option '--{$arg}' is not supported under {$system_name}.".
|
|
|
|
$extended_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function normalizeRevisionID($revision_id) {
|
|
|
|
return ltrim(strtoupper($revision_id), 'D');
|
|
|
|
}
|
|
|
|
|
2011-01-15 05:00:11 +01:00
|
|
|
protected function shouldShellComplete() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getShellCompletions(array $argv) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getSupportedRevisionControlSystems() {
|
|
|
|
return array('any');
|
|
|
|
}
|
|
|
|
|
2011-02-02 05:32:10 +01:00
|
|
|
protected function getPassthruArgumentsAsMap($command) {
|
|
|
|
$map = array();
|
|
|
|
foreach ($this->getCompleteArgumentSpecification() as $key => $spec) {
|
|
|
|
if (!empty($spec['passthru'][$command])) {
|
|
|
|
if (isset($this->arguments[$key])) {
|
|
|
|
$map[$key] = $this->arguments[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getPassthruArgumentsAsArgv($command) {
|
|
|
|
$spec = $this->getCompleteArgumentSpecification();
|
|
|
|
$map = $this->getPassthruArgumentsAsMap($command);
|
|
|
|
$argv = array();
|
|
|
|
foreach ($map as $key => $value) {
|
|
|
|
$argv[] = '--'.$key;
|
|
|
|
if (!empty($spec[$key]['param'])) {
|
|
|
|
$argv[] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $argv;
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:18:40 +02:00
|
|
|
public static function getUserConfigurationFileLocation() {
|
2012-03-05 19:02:37 +01:00
|
|
|
if (phutil_is_windows()) {
|
|
|
|
return getenv('APPDATA').'/.arcrc';
|
|
|
|
} else {
|
|
|
|
return getenv('HOME').'/.arcrc';
|
|
|
|
}
|
2011-06-14 21:18:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function readUserConfigurationFile() {
|
|
|
|
$user_config = array();
|
|
|
|
$user_config_path = self::getUserConfigurationFileLocation();
|
|
|
|
if (Filesystem::pathExists($user_config_path)) {
|
2012-03-05 19:02:37 +01:00
|
|
|
|
|
|
|
if (!phutil_is_windows()) {
|
|
|
|
$mode = fileperms($user_config_path);
|
|
|
|
if (!$mode) {
|
|
|
|
throw new Exception("Unable to get perms of '{$user_config_path}'!");
|
|
|
|
}
|
|
|
|
if ($mode & 0177) {
|
|
|
|
// Mode should allow only owner access.
|
|
|
|
$prompt = "File permissions on your ~/.arcrc are too open. ".
|
|
|
|
"Fix them by chmod'ing to 600?";
|
|
|
|
if (!phutil_console_confirm($prompt, $default_no = false)) {
|
|
|
|
throw new ArcanistUsageException("Set ~/.arcrc to file mode 600.");
|
|
|
|
}
|
|
|
|
execx('chmod 600 %s', $user_config_path);
|
2012-06-14 21:30:21 +02:00
|
|
|
|
|
|
|
// Drop the stat cache so we don't read the old permissions if
|
|
|
|
// we end up here again. If we don't do this, we may prompt the user
|
|
|
|
// to fix permissions multiple times.
|
|
|
|
clearstatcache();
|
Verify that ~/.arcrc is 600 before reading from it
Summary:
Since this has auth information in it now, we should prevent other users on the
system from reading it. Detect readable files and prompt the user to fix them.
Test Plan:
Did "o+r" on my ~/.arcrc, ran "arc list", got prompted, hit "Y", verified it set
perms to 600, ran "arc list" again and wasn't prompted.
Reviewed By: jungejason
Reviewers: fratrik, jungejason, aran, tuomaspelkonen
CC: aran, jungejason, epriestley
Differential Revision: 532
2011-06-26 20:09:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:18:40 +02:00
|
|
|
$user_config_data = Filesystem::readFile($user_config_path);
|
|
|
|
$user_config = json_decode($user_config_data, true);
|
|
|
|
if (!is_array($user_config)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Your '~/.arcrc' file is not a valid JSON file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $user_config;
|
|
|
|
}
|
|
|
|
|
2012-02-21 22:16:52 +01:00
|
|
|
|
|
|
|
public static function writeUserConfigurationFile($config) {
|
|
|
|
$json_encoder = new PhutilJSON();
|
|
|
|
$json = $json_encoder->encodeFormatted($config);
|
|
|
|
|
|
|
|
$path = self::getUserConfigurationFileLocation();
|
|
|
|
Filesystem::writeFile($path, $json);
|
2012-03-05 19:02:37 +01:00
|
|
|
|
|
|
|
if (!phutil_is_windows()) {
|
|
|
|
execx('chmod 600 %s', $path);
|
|
|
|
}
|
2012-02-21 22:16:52 +01:00
|
|
|
}
|
|
|
|
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
public static function readGlobalArcConfig() {
|
2012-05-07 15:07:23 +02:00
|
|
|
return idx(self::readUserConfigurationFile(), 'config', array());
|
|
|
|
}
|
|
|
|
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
public static function writeGlobalArcConfig(array $options) {
|
2012-05-07 15:07:23 +02:00
|
|
|
$config = self::readUserConfigurationFile();
|
|
|
|
$config['config'] = $options;
|
|
|
|
self::writeUserConfigurationFile($config);
|
|
|
|
}
|
|
|
|
|
2012-06-14 01:02:29 +02:00
|
|
|
public function readLocalArcConfig() {
|
|
|
|
$local = array();
|
|
|
|
$file = $this->readScratchFile('config');
|
|
|
|
if ($file) {
|
|
|
|
$local = json_decode($file, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $local;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function writeLocalArcConfig(array $config) {
|
|
|
|
$json_encoder = new PhutilJSON();
|
|
|
|
$json = $json_encoder->encodeFormatted($config);
|
|
|
|
|
|
|
|
$this->writeScratchFile('config', $json);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-02-21 22:16:52 +01:00
|
|
|
|
2011-07-30 05:17:49 +02:00
|
|
|
/**
|
|
|
|
* Write a message to stderr so that '--json' flags or stdout which is meant
|
|
|
|
* to be piped somewhere aren't disrupted.
|
|
|
|
*
|
|
|
|
* @param string Message to write to stderr.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function writeStatusMessage($msg) {
|
|
|
|
file_put_contents('php://stderr', $msg);
|
|
|
|
}
|
|
|
|
|
2011-08-26 02:53:59 +02:00
|
|
|
protected function isHistoryImmutable() {
|
2012-06-04 21:30:50 +02:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
2011-08-26 02:53:59 +02:00
|
|
|
$working_copy = $this->getWorkingCopy();
|
2012-06-04 21:30:50 +02:00
|
|
|
|
2012-06-11 16:15:28 +02:00
|
|
|
$project_config = $working_copy->getConfigFromAnySource('immutable_history');
|
2012-06-04 21:30:50 +02:00
|
|
|
if ($project_config !== null) {
|
|
|
|
return $project_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $repository_api->isHistoryDefaultImmutable();
|
2011-08-26 02:53:59 +02:00
|
|
|
}
|
|
|
|
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
/**
|
|
|
|
* Workflows like 'lint' and 'unit' operate on a list of working copy paths.
|
|
|
|
* The user can either specify the paths explicitly ("a.js b.php"), or by
|
|
|
|
* specfifying a revision ("--rev a3f10f1f") to select all paths modified
|
|
|
|
* since that revision, or by omitting both and letting arc choose the
|
|
|
|
* default relative revision.
|
|
|
|
*
|
|
|
|
* This method takes the user's selections and returns the paths that the
|
|
|
|
* workflow should act upon.
|
|
|
|
*
|
|
|
|
* @param list List of explicitly provided paths.
|
|
|
|
* @param string|null Revision name, if provided.
|
2012-03-13 01:04:20 +01:00
|
|
|
* @param mask Mask of ArcanistRepositoryAPI flags to exclude.
|
|
|
|
* Defaults to ArcanistRepositoryAPI::FLAG_UNTRACKED.
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
* @return list List of paths the workflow should act on.
|
|
|
|
*/
|
2012-03-13 01:04:20 +01:00
|
|
|
protected function selectPathsForWorkflow(
|
|
|
|
array $paths,
|
|
|
|
$rev,
|
|
|
|
$omit_mask = null) {
|
|
|
|
|
|
|
|
if ($omit_mask === null) {
|
|
|
|
$omit_mask = ArcanistRepositoryAPI::FLAG_UNTRACKED;
|
|
|
|
}
|
|
|
|
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
if ($paths) {
|
|
|
|
$working_copy = $this->getWorkingCopy();
|
|
|
|
foreach ($paths as $key => $path) {
|
|
|
|
$full_path = Filesystem::resolvePath($path);
|
|
|
|
if (!Filesystem::pathExists($full_path)) {
|
|
|
|
throw new ArcanistUsageException("Path '{$path}' does not exist!");
|
|
|
|
}
|
|
|
|
$relative_path = Filesystem::readablePath(
|
|
|
|
$full_path,
|
|
|
|
$working_copy->getProjectRoot());
|
|
|
|
$paths[$key] = $relative_path;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
if ($rev) {
|
|
|
|
$repository_api->parseRelativeLocalCommit(array($rev));
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = $repository_api->getWorkingCopyStatus();
|
|
|
|
foreach ($paths as $path => $flags) {
|
2012-03-13 01:04:20 +01:00
|
|
|
if ($flags & $omit_mask) {
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 21:40:50 +01:00
|
|
|
unset($paths[$path]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$paths = array_keys($paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_values($paths);
|
|
|
|
}
|
|
|
|
|
Add "arc land" as a first-class workflow
Summary:
This is a fancy version of "land.sh" that uses "git merge --squash" and
"arc which" to cover more cases.
Test Plan:
Ran "arc land" against various repository states (no such branch, not
accepted, valid, etc). Things seemed OK. There are basically an infinite number
of states here so it's hard to test exhaustively.
Reviewers: cpiro, btrahan, jungejason, davidreuss
Reviewed By: davidreuss
CC: zeeg, aran, epriestley, davidreuss
Maniphest Tasks: T787, T723
Differential Revision: https://secure.phabricator.com/D1488
2012-01-26 00:10:59 +01:00
|
|
|
protected function renderRevisionList(array $revisions) {
|
|
|
|
$list = array();
|
|
|
|
foreach ($revisions as $revision) {
|
|
|
|
$list[] = ' - D'.$revision['id'].': '.$revision['title']."\n";
|
|
|
|
}
|
|
|
|
return implode('', $list);
|
|
|
|
}
|
|
|
|
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
|
2012-02-21 21:35:39 +01:00
|
|
|
/* -( Scratch Files )------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to read a scratch file, if it exists and is readable.
|
|
|
|
*
|
|
|
|
* @param string Scratch file name.
|
|
|
|
* @return mixed String for file contents, or false for failure.
|
|
|
|
* @task scratch
|
|
|
|
*/
|
|
|
|
protected function readScratchFile($path) {
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
if (!$this->repositoryAPI) {
|
2012-02-21 21:35:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
return $this->getRepositoryAPI()->readScratchFile($path);
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to write a scratch file, if there's somewhere to put it and we can
|
|
|
|
* write there.
|
|
|
|
*
|
|
|
|
* @param string Scratch file name to write.
|
|
|
|
* @param string Data to write.
|
|
|
|
* @return bool True on success, false on failure.
|
|
|
|
* @task scratch
|
|
|
|
*/
|
|
|
|
protected function writeScratchFile($path, $data) {
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
if (!$this->repositoryAPI) {
|
2012-02-21 21:35:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
return $this->getRepositoryAPI()->writeScratchFile($path, $data);
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to remove a scratch file.
|
|
|
|
*
|
|
|
|
* @param string Scratch file name to remove.
|
|
|
|
* @return bool True if the file was removed successfully.
|
|
|
|
* @task scratch
|
|
|
|
*/
|
|
|
|
protected function removeScratchFile($path) {
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
if (!$this->repositoryAPI) {
|
2012-02-21 21:35:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
return $this->getRepositoryAPI()->removeScratchFile($path);
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a human-readable description of the scratch file location.
|
|
|
|
*
|
|
|
|
* @param string Scratch file name.
|
|
|
|
* @return mixed String, or false on failure.
|
|
|
|
* @task scratch
|
|
|
|
*/
|
|
|
|
protected function getReadableScratchFilePath($path) {
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
if (!$this->repositoryAPI) {
|
2012-02-21 21:35:39 +01:00
|
|
|
return false;
|
|
|
|
}
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
return $this->getRepositoryAPI()->getReadableScratchFilePath($path);
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the path to a scratch file, if possible.
|
|
|
|
*
|
|
|
|
* @param string Scratch file name.
|
|
|
|
* @return mixed File path, or false on failure.
|
|
|
|
* @task scratch
|
|
|
|
*/
|
|
|
|
protected function getScratchFilePath($path) {
|
|
|
|
if (!$this->repositoryAPI) {
|
|
|
|
return false;
|
|
|
|
}
|
Revenge of the git relative commit default
Summary:
The default of "arc diff" to "arc diff HEAD^" in git is universally confusing to everyone not at Facebook.
Drive the default with configuration instead. Even at Facebook, "origin/trunk" (or whatever) is probably a better default than "HEAD^".
See D863 for the last attempt at this.
NOTE: This is contentious!
Test Plan: Ran "arc diff", got prompted to set a default. Ran "arc diff" from a zero-commit repo, got sensible behavior
Reviewers: btrahan, vrana, nh, jungejason, tuomaspelkonen
Reviewed By: btrahan
CC: aran, epriestley, zeeg, davidreuss
Maniphest Tasks: T651
Differential Revision: https://secure.phabricator.com/D1861
2012-04-03 01:52:20 +02:00
|
|
|
return $this->getRepositoryAPI()->getScratchFilePath($path);
|
2012-02-21 21:35:39 +01:00
|
|
|
}
|
|
|
|
|
2012-03-14 15:08:06 +01:00
|
|
|
protected function getRepositoryEncoding() {
|
|
|
|
if ($this->repositoryEncoding) {
|
|
|
|
return $this->repositoryEncoding;
|
|
|
|
}
|
|
|
|
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
$default = 'UTF-8';
|
|
|
|
|
|
|
|
$project_id = $this->getWorkingCopy()->getProjectID();
|
|
|
|
if (!$project_id) {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2012-03-14 15:08:06 +01:00
|
|
|
$project_info = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'arcanist.projectinfo',
|
|
|
|
array(
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
'name' => $project_id,
|
2012-03-14 15:08:06 +01:00
|
|
|
));
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
|
|
|
|
$this->repositoryEncoding = nonempty($project_info['encoding'], $default);
|
|
|
|
|
2012-03-14 15:08:06 +01:00
|
|
|
return $this->repositoryEncoding;
|
|
|
|
}
|
|
|
|
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 20:41:39 +02:00
|
|
|
protected static function formatConfigValueForDisplay($value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
// TODO: Both json_encode() and PhutilJSON do a bad job with one-liners.
|
|
|
|
// PhutilJSON splits them across a bunch of lines, while json_encode()
|
|
|
|
// escapes all kinds of stuff like "/". It would be nice if PhutilJSON
|
|
|
|
// had a mode for pretty one-liners.
|
|
|
|
$value = json_encode($value);
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|