array( 'help' => "Show the amended commit message, without modifying the working copy." ), 'revision' => array( 'param' => 'revision_id', 'help' => "Amend a specific revision. If you do not specify a revision, ". "arc will look in the commit message at HEAD.", ), ); } public function run() { $is_show = $this->getArgument('show'); $repository_api = $this->getRepositoryAPI(); if (!($repository_api instanceof ArcanistGitAPI)) { throw new ArcanistUsageException( "You may only run 'arc amend' in a git working copy."); } if (!$is_show) { if ($this->isHistoryImmutable()) { throw new ArcanistUsageException( "This project is marked as adhering to a conservative history ". "mutability doctrine (having an immutable local history), which ". "precludes amending commit messages. You can use 'arc merge' to ". "merge feature branches instead."); } if ($repository_api->getUncommittedChanges()) { throw new ArcanistUsageException( "You have uncommitted changes in this branch. Stage and commit (or ". "revert) them before proceeding."); } } if ($this->getArgument('revision')) { $revision_id = $this->getArgument('revision'); } else { $log = $repository_api->getGitCommitLog(); $parser = new ArcanistDiffParser(); $changes = $parser->parseDiff($log); if (count($changes) != 1) { throw new Exception("Expected one log."); } $change = reset($changes); if ($change->getType() != ArcanistDiffChangeType::TYPE_MESSAGE) { throw new Exception("Expected message change."); } $message = ArcanistDifferentialCommitMessage::newFromRawCorpus( $change->getMetadata('message')); $revision_id = $message->getRevisionID(); if (!$revision_id) { throw new ArcanistUsageException( "No revision specified with '--revision', and no Differential ". "revision marker in HEAD."); } } // TODO: The old 'arc amend' had a check here to see if you were running // 'arc amend' with an explicit revision but HEAD already had another // revision in it. Maybe this is worth restoring? $conduit = $this->getConduit(); $message = $conduit->callMethodSynchronous( 'differential.getcommitmessage', array( 'revision_id' => $revision_id, 'edit' => false, )); if ($is_show) { echo $message."\n"; } else { $repository_api->amendGitHeadCommit($message); echo "Amended commit message.\n"; $mark_workflow = $this->buildChildWorkflow( 'mark-committed', array( '--finalize', $revision_id, )); $mark_workflow->run(); } return 0; } protected function getSupportedRevisionControlSystems() { return array('git'); } }