Path: blob/master/src/applications/differential/management/PhabricatorDifferentialAttachCommitWorkflow.php
12256 views
<?php12final class PhabricatorDifferentialAttachCommitWorkflow3extends PhabricatorDifferentialManagementWorkflow {45protected function didConstruct() {6$this7->setName('attach-commit')8->setExamples('**attach-commit** __commit__ __revision__')9->setSynopsis(pht('Forcefully attach a commit to a revision.'))10->setArguments(11array(12array(13'name' => 'argv',14'wildcard' => true,15'help' => pht('Commit, and a revision to attach it to.'),16),17));18}1920public function execute(PhutilArgumentParser $args) {21$viewer = $this->getViewer();2223$argv = $args->getArg('argv');24if (count($argv) !== 2) {25throw new PhutilArgumentUsageException(26pht('Specify a commit and a revision to attach it to.'));27}2829$commit_name = head($argv);30$revision_name = last($argv);3132$commit = id(new DiffusionCommitQuery())33->setViewer($viewer)34->withIdentifiers(array($commit_name))35->executeOne();36if (!$commit) {37throw new PhutilArgumentUsageException(38pht('Commit "%s" does not exist.', $commit_name));39}4041$revision = id(new PhabricatorObjectQuery())42->setViewer($viewer)43->withNames(array($revision_name))44->executeOne();4546if (!$revision) {47throw new PhutilArgumentUsageException(48pht('Revision "%s" does not exist.', $revision_name));49}5051if (!($revision instanceof DifferentialRevision)) {52throw new PhutilArgumentUsageException(53pht('Object "%s" must be a Differential revision.', $revision_name));54}5556// Reload the revision to get the active diff.57$revision = id(new DifferentialRevisionQuery())58->setViewer($viewer)59->withIDs(array($revision->getID()))60->needActiveDiffs(true)61->executeOne();6263$differential_phid = id(new PhabricatorDifferentialApplication())64->getPHID();6566$extraction_engine = id(new DifferentialDiffExtractionEngine())67->setViewer($viewer)68->setAuthorPHID($differential_phid);6970$content_source = $this->newContentSource();7172$extraction_engine->updateRevisionWithCommit(73$revision,74$commit,75array(),76$content_source);7778echo tsprintf(79"%s\n",80pht(81'Attached "%s" to "%s".',82$commit->getMonogram(),83$revision->getMonogram()));84}858687}888990