Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistBackoutWorkflow.php
| Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | private function getCommitIDFromRevisionID($revision_id) { | ||||
| $conduit = $this->getConduit(); | $conduit = $this->getConduit(); | ||||
| $revisions = $conduit->callMethodSynchronous( | $revisions = $conduit->callMethodSynchronous( | ||||
| 'differential.query', | 'differential.query', | ||||
| array( | array( | ||||
| 'ids' => array($revision_id), | 'ids' => array($revision_id), | ||||
| )); | )); | ||||
| if (!$revisions) { | if (!$revisions) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'The revision you provided does not exist!'); | pht('The revision you provided does not exist!')); | ||||
| } | } | ||||
| $revision = $revisions[0]; | $revision = $revisions[0]; | ||||
| $commits = $revision['commits']; | $commits = $revision['commits']; | ||||
| if (!$commits) { | if (!$commits) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'This revision has not been committed yet!'); | pht('This revision has not been committed yet!')); | ||||
| } else if (count($commits) > 1) { | } else if (count($commits) > 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'The revision you provided has multiple commits!'); | pht('The revision you provided has multiple commits!')); | ||||
| } | } | ||||
| $commit_phid = $commits[0]; | $commit_phid = $commits[0]; | ||||
| $commit = $conduit->callMethodSynchronous( | $commit = $conduit->callMethodSynchronous( | ||||
| 'phid.query', | 'phid.query', | ||||
| array( | array( | ||||
| 'phids' => array($commit_phid), | 'phids' => array($commit_phid), | ||||
| )); | )); | ||||
| $commit_id = $commit[$commit_phid]['name']; | $commit_id = $commit[$commit_phid]['name']; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public function run() { | ||||
| $repository_api = $this->getRepositoryAPI(); | $repository_api = $this->getRepositoryAPI(); | ||||
| $is_git_svn = $repository_api instanceof ArcanistGitAPI && | $is_git_svn = $repository_api instanceof ArcanistGitAPI && | ||||
| $repository_api->isGitSubversionRepo(); | $repository_api->isGitSubversionRepo(); | ||||
| $is_hg_svn = $repository_api instanceof ArcanistMercurialAPI && | $is_hg_svn = $repository_api instanceof ArcanistMercurialAPI && | ||||
| $repository_api->isHgSubversionRepo(); | $repository_api->isHgSubversionRepo(); | ||||
| $revision_id = null; | $revision_id = null; | ||||
| $console->writeOut("Starting backout\n"); | $console->writeOut(pht('Starting backout.')."\n"); | ||||
| $input = $this->getArgument('input'); | $input = $this->getArgument('input'); | ||||
| if (!$input || count($input) != 1) { | if (!$input || count($input) != 1) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'You must specify one commit to backout!'); | pht('You must specify one commit to backout!')); | ||||
| } | } | ||||
| // Input looks like a Differential revision, so | // Input looks like a Differential revision, so | ||||
| // we try to find the commit attached to it | // we try to find the commit attached to it | ||||
| $matches = array(); | $matches = array(); | ||||
| if (preg_match('/^D(\d+)$/i', $input[0], $matches)) { | if (preg_match('/^D(\d+)$/i', $input[0], $matches)) { | ||||
| $revision_id = $matches[1]; | $revision_id = $matches[1]; | ||||
| $commit_id = $this->getCommitIDFromRevisionID($revision_id); | $commit_id = $this->getCommitIDFromRevisionID($revision_id); | ||||
| Show All 10 Lines | public function run() { | ||||
| } | } | ||||
| if (!$repository_api->hasLocalCommit($commit_hash)) { | if (!$repository_api->hasLocalCommit($commit_hash)) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| 'Invalid commit provided or does not exist in the working copy!'); | 'Invalid commit provided or does not exist in the working copy!'); | ||||
| } | } | ||||
| // Run 'backout'. | // Run 'backout'. | ||||
| $subject = $repository_api->getCommitSummary($commit_hash); | $subject = $repository_api->getCommitSummary($commit_hash); | ||||
| $console->writeOut("Backing out commit {$commit_hash} {$subject} \n"); | $console->writeOut( | ||||
| pht('Backing out commit %s %s', $commit_hash, $subject)."\n"); | |||||
| $repository_api->backoutCommit($commit_hash); | $repository_api->backoutCommit($commit_hash); | ||||
| // Create commit message and execute the commit | // Create commit message and execute the commit | ||||
| $message = $this->buildCommitMessage($commit_hash); | $message = $this->buildCommitMessage($commit_hash); | ||||
| $repository_api->doCommit($message); | $repository_api->doCommit($message); | ||||
| $console->writeOut("Double-check the commit and push when ready\n"); | $console->writeOut(pht('Double-check the commit and push when ready.')."\n"); | ||||
| } | } | ||||
| } | } | ||||