Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistBaseWorkflow.php
| Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | /* -( Conduit )------------------------------------------------------------ */ | ||||
| * @param string The URI to open a conduit to when @{method:establishConduit} | * @param string The URI to open a conduit to when @{method:establishConduit} | ||||
| * is called. | * is called. | ||||
| * @return this | * @return this | ||||
| * @task conduit | * @task conduit | ||||
| */ | */ | ||||
| final public function setConduitURI($conduit_uri) { | final public function setConduitURI($conduit_uri) { | ||||
| if ($this->conduit) { | if ($this->conduit) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "You can not change the Conduit URI after a conduit is already open."); | 'You can not change the Conduit URI after a conduit is already open.'); | ||||
| } | } | ||||
| $this->conduitURI = $conduit_uri; | $this->conduitURI = $conduit_uri; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * Returns the URI the conduit connection within the workflow uses. | * Returns the URI the conduit connection within the workflow uses. | ||||
| * | * | ||||
| Show All 20 Lines | /* -( Conduit )------------------------------------------------------------ */ | ||||
| */ | */ | ||||
| final public function establishConduit() { | final public function establishConduit() { | ||||
| if ($this->conduit) { | if ($this->conduit) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| if (!$this->conduitURI) { | if (!$this->conduitURI) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "You must specify a Conduit URI with setConduitURI() before you can ". | 'You must specify a Conduit URI with setConduitURI() before you can '. | ||||
| "establish a conduit."); | 'establish a conduit.'); | ||||
| } | } | ||||
| $this->conduit = new ConduitClient($this->conduitURI); | $this->conduit = new ConduitClient($this->conduitURI); | ||||
| if ($this->conduitTimeout) { | if ($this->conduitTimeout) { | ||||
| $this->conduit->setTimeout($this->conduitTimeout); | $this->conduit->setTimeout($this->conduitTimeout); | ||||
| } | } | ||||
| Show All 28 Lines | /* -( Conduit )------------------------------------------------------------ */ | ||||
| * | * | ||||
| * @param dict A credential dictionary, see @{method:authenticateConduit}. | * @param dict A credential dictionary, see @{method:authenticateConduit}. | ||||
| * @return this | * @return this | ||||
| * @task conduit | * @task conduit | ||||
| */ | */ | ||||
| final public function setConduitCredentials(array $credentials) { | final public function setConduitCredentials(array $credentials) { | ||||
| if ($this->isConduitAuthenticated()) { | if ($this->isConduitAuthenticated()) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "You may not set new credentials after authenticating conduit."); | 'You may not set new credentials after authenticating conduit.'); | ||||
| } | } | ||||
| $this->conduitCredentials = $credentials; | $this->conduitCredentials = $credentials; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | final public function authenticateConduit() { | ||||
| } | } | ||||
| $this->establishConduit(); | $this->establishConduit(); | ||||
| $credentials = $this->conduitCredentials; | $credentials = $this->conduitCredentials; | ||||
| try { | try { | ||||
| if (!$credentials) { | if (!$credentials) { | ||||
| throw new Exception( | throw new Exception( | ||||
| "Set conduit credentials with setConduitCredentials() before ". | 'Set conduit credentials with setConduitCredentials() before '. | ||||
| "authenticating conduit!"); | 'authenticating conduit!'); | ||||
| } | } | ||||
| if (empty($credentials['user'])) { | if (empty($credentials['user'])) { | ||||
| throw new ConduitClientException('ERR-INVALID-USER', | throw new ConduitClientException('ERR-INVALID-USER', | ||||
| 'Empty user in credentials.'); | 'Empty user in credentials.'); | ||||
| } | } | ||||
| if (empty($credentials['certificate'])) { | if (empty($credentials['certificate'])) { | ||||
| throw new ConduitClientException('ERR-NO-CERTIFICATE', | throw new ConduitClientException('ERR-NO-CERTIFICATE', | ||||
| Show All 16 Lines | try { | ||||
| )); | )); | ||||
| } catch (ConduitClientException $ex) { | } catch (ConduitClientException $ex) { | ||||
| if ($ex->getErrorCode() == 'ERR-NO-CERTIFICATE' || | if ($ex->getErrorCode() == 'ERR-NO-CERTIFICATE' || | ||||
| $ex->getErrorCode() == 'ERR-INVALID-USER') { | $ex->getErrorCode() == 'ERR-INVALID-USER') { | ||||
| $conduit_uri = $this->conduitURI; | $conduit_uri = $this->conduitURI; | ||||
| $message = | $message = | ||||
| "\n". | "\n". | ||||
| phutil_console_format( | phutil_console_format( | ||||
| "YOU NEED TO __INSTALL A CERTIFICATE__ TO LOGIN TO PHABRICATOR"). | 'YOU NEED TO __INSTALL A CERTIFICATE__ TO LOGIN TO PHABRICATOR'). | ||||
| "\n\n". | "\n\n". | ||||
| phutil_console_format( | phutil_console_format( | ||||
| " To do this, run: **arc install-certificate**"). | ' To do this, run: **arc install-certificate**'). | ||||
| "\n\n". | "\n\n". | ||||
| "The server '{$conduit_uri}' rejected your request:". | "The server '{$conduit_uri}' rejected your request:". | ||||
| "\n". | "\n". | ||||
| $ex->getMessage(); | $ex->getMessage(); | ||||
| throw new ArcanistUsageException($message); | throw new ArcanistUsageException($message); | ||||
| } else if ($ex->getErrorCode() == 'NEW-ARC-VERSION') { | } else if ($ex->getErrorCode() == 'NEW-ARC-VERSION') { | ||||
| // Cleverly disguise this as being AWESOME!!! | // Cleverly disguise this as being AWESOME!!! | ||||
| echo phutil_console_format("**New Version Available!**\n\n"); | echo phutil_console_format("**New Version Available!**\n\n"); | ||||
| echo phutil_console_wrap($ex->getMessage()); | echo phutil_console_wrap($ex->getMessage()); | ||||
| echo "\n\n"; | echo "\n\n"; | ||||
| echo "In most cases, arc can be upgraded automatically.\n"; | echo "In most cases, arc can be upgraded automatically.\n"; | ||||
| $ok = phutil_console_confirm( | $ok = phutil_console_confirm( | ||||
| "Upgrade arc now?", | 'Upgrade arc now?', | ||||
| $default_no = false); | $default_no = false); | ||||
| if (!$ok) { | if (!$ok) { | ||||
| throw $ex; | throw $ex; | ||||
| } | } | ||||
| $root = dirname(phutil_get_library_root('arcanist')); | $root = dirname(phutil_get_library_root('arcanist')); | ||||
| chdir($root); | chdir($root); | ||||
| ▲ Show 20 Lines • Show All 512 Lines • ▼ Show 20 Lines | if ($unstaged) { | ||||
| false); | false); | ||||
| if ($permit_autostash && $api->canStashChanges()) { | if ($permit_autostash && $api->canStashChanges()) { | ||||
| echo "Stashing uncommitted changes. (You can restore them with ". | echo "Stashing uncommitted changes. (You can restore them with ". | ||||
| "`git stash pop`.)\n"; | "`git stash pop`.)\n"; | ||||
| $api->stashChanges(); | $api->stashChanges(); | ||||
| $this->stashed = true; | $this->stashed = true; | ||||
| } else { | } else { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Stage and commit (or revert) them before proceeding."); | 'Stage and commit (or revert) them before proceeding.'); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $uncommitted = $api->getUncommittedChanges(); | $uncommitted = $api->getUncommittedChanges(); | ||||
| foreach ($uncommitted as $key => $path) { | foreach ($uncommitted as $key => $path) { | ||||
| if (array_key_exists($path, $must_commit)) { | if (array_key_exists($path, $must_commit)) { | ||||
| unset($uncommitted[$key]); | unset($uncommitted[$key]); | ||||
| } | } | ||||
| } | } | ||||
| if ($uncommitted) { | if ($uncommitted) { | ||||
| echo "You have uncommitted changes in this working copy.\n\n". | echo "You have uncommitted changes in this working copy.\n\n". | ||||
| $working_copy_desc. | $working_copy_desc. | ||||
| " Uncommitted changes in working copy:\n". | " Uncommitted changes in working copy:\n". | ||||
| " ".implode("\n ", $uncommitted)."\n"; | " ".implode("\n ", $uncommitted)."\n"; | ||||
| if ($this->askForAdd($uncommitted)) { | if ($this->askForAdd($uncommitted)) { | ||||
| $must_commit += array_flip($uncommitted); | $must_commit += array_flip($uncommitted); | ||||
| } else { | } else { | ||||
| throw new ArcanistUncommittedChangesException( | throw new ArcanistUncommittedChangesException( | ||||
| "Commit (or revert) them before proceeding."); | 'Commit (or revert) them before proceeding.'); | ||||
| } | } | ||||
| } | } | ||||
| if ($must_commit) { | if ($must_commit) { | ||||
| if ($this->getShouldAmend()) { | if ($this->getShouldAmend()) { | ||||
| $commit = head($api->getLocalCommitInformation()); | $commit = head($api->getLocalCommitInformation()); | ||||
| $api->amendCommit($commit['message']); | $api->amendCommit($commit['message']); | ||||
| } else if ($api->supportsLocalCommits()) { | } else if ($api->supportsLocalCommits()) { | ||||
| $commit_message = phutil_console_prompt("Enter commit message:"); | $commit_message = phutil_console_prompt('Enter commit message:'); | ||||
| if ($commit_message == '') { | if ($commit_message == '') { | ||||
| $commit_message = self::AUTO_COMMIT_TITLE; | $commit_message = self::AUTO_COMMIT_TITLE; | ||||
| } | } | ||||
| $api->doCommit($commit_message); | $api->doCommit($commit_message); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | final protected function getChange($path) { | ||||
| if ($is_svn) { | if ($is_svn) { | ||||
| // NOTE: In SVN, we don't currently support a "get all local changes" | // NOTE: In SVN, we don't currently support a "get all local changes" | ||||
| // operation, so special case it. | // operation, so special case it. | ||||
| if (empty($this->changeCache[$path])) { | if (empty($this->changeCache[$path])) { | ||||
| $diff = $repository_api->getRawDiffText($path); | $diff = $repository_api->getRawDiffText($path); | ||||
| $parser = $this->newDiffParser(); | $parser = $this->newDiffParser(); | ||||
| $changes = $parser->parseDiff($diff); | $changes = $parser->parseDiff($diff); | ||||
| if (count($changes) != 1) { | if (count($changes) != 1) { | ||||
| throw new Exception("Expected exactly one change."); | throw new Exception('Expected exactly one change.'); | ||||
| } | } | ||||
| $this->changeCache[$path] = reset($changes); | $this->changeCache[$path] = reset($changes); | ||||
| } | } | ||||
| } else if ($is_git || $is_hg) { | } else if ($is_git || $is_hg) { | ||||
| if (empty($this->changeCache)) { | if (empty($this->changeCache)) { | ||||
| $changes = $repository_api->getAllLocalChanges(); | $changes = $repository_api->getAllLocalChanges(); | ||||
| foreach ($changes as $change) { | foreach ($changes as $change) { | ||||
| $this->changeCache[$change->getCurrentPath()] = $change; | $this->changeCache[$change->getCurrentPath()] = $change; | ||||
| } | } | ||||
| } | } | ||||
| } else { | } else { | ||||
| throw new Exception("Missing VCS support."); | throw new Exception('Missing VCS support.'); | ||||
| } | } | ||||
| if (empty($this->changeCache[$path])) { | if (empty($this->changeCache[$path])) { | ||||
| if ($is_git || $is_hg) { | if ($is_git || $is_hg) { | ||||
| // This can legitimately occur under git/hg if you make a change, | // This can legitimately occur under git/hg if you make a change, | ||||
| // "git/hg commit" it, and then revert the change in the working copy | // "git/hg commit" it, and then revert the change in the working copy | ||||
| // and run "arc lint". | // and run "arc lint". | ||||
| $change = new ArcanistDiffChange(); | $change = new ArcanistDiffChange(); | ||||
| ▲ Show 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | /* -( Scratch Files )------------------------------------------------------ */ | ||||
| final public function parseBaseCommitArgument(array $argv) { | final public function parseBaseCommitArgument(array $argv) { | ||||
| if (!count($argv)) { | if (!count($argv)) { | ||||
| return; | return; | ||||
| } | } | ||||
| $api = $this->getRepositoryAPI(); | $api = $this->getRepositoryAPI(); | ||||
| if (!$api->supportsCommitRanges()) { | if (!$api->supportsCommitRanges()) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "This version control system does not support commit ranges."); | 'This version control system does not support commit ranges.'); | ||||
| } | } | ||||
| if (count($argv) > 1) { | if (count($argv) > 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Specify exactly one base commit. The end of the commit range is ". | 'Specify exactly one base commit. The end of the commit range is '. | ||||
| "always the working copy state."); | 'always the working copy state.'); | ||||
| } | } | ||||
| $api->setBaseCommit(head($argv)); | $api->setBaseCommit(head($argv)); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final protected function getRepositoryVersion() { | final protected function getRepositoryVersion() { | ||||
| ▲ Show 20 Lines • Show All 269 Lines • Show Last 20 Lines | |||||