From: epriestley Date: Fri, 2 Dec 2011 23:50:36 +0000 (-0800) Subject: Add an experimental "--create" flag to "arc diff" X-Git-Tag: conduit-4~222 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=331afdce87c88027a789ee1772eb1d5633a7864f;p=arcanist.git Add an experimental "--create" flag to "arc diff" Summary: See T614. This adds a "--create" flag which I think works properly, but doesn't make it the default. Once I add "--update" and am confident the flags actually work, I'll work on some heuristics to make "arc diff" automatically choose "--udpate" or "--create" as per T614. Test Plan: This revision was created with "--create" and a bogus commit message ("derp"). I intentionally goofed the message at first to test the fail + file workflow. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley, btrahan Differential Revision: 1162 --- diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index 4d2a8314..9cf0bb62 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -32,8 +32,8 @@ class ArcanistDiffWorkflow extends ArcanistBaseWorkflow { public function getCommandHelp() { return phutil_console_format(<< array( + 'short' => 'F', + 'param' => 'file', + 'paramtype' => 'file', + 'help' => 'When creating a revision, read revision information '. + 'from this file.', + ), 'edit' => array( 'supports' => array( 'git', @@ -93,6 +100,12 @@ EOTEXT "When updating a revision under git, edit revision information ". "before updating.", ), + 'create' => array( + 'help' => "(EXPERIMENTAL) Create a new revision.", + 'conflicts' => array( + 'edit' => '--create can not be used with --edit.', + ), + ), 'nounit' => array( 'help' => "Do not run unit tests.", @@ -211,6 +224,8 @@ EOTEXT ob_start(); } + $is_create = $this->getArgument('create'); + $conduit = $this->getConduit(); $this->requireCleanWorkingCopy(); @@ -220,7 +235,14 @@ EOTEXT // Do this before we start linting or running unit tests so we can detect // things like a missing test plan or invalid reviewers immediately. - if ($this->shouldOnlyCreateDiff()) { + if ($is_create) { + $message_file = $this->getArgument('message-file'); + if ($message_file) { + $commit_message = $this->getCommitMessageFromFile($message_file); + } else { + $commit_message = $this->getCommitMessageFromUser(); + } + } else if ($this->shouldOnlyCreateDiff()) { $commit_message = null; } else { $commit_message = $this->getGitCommitMessage(); @@ -411,8 +433,6 @@ EOTEXT $remote_corpus); $remote_message->pullDataFromConduit($conduit); - // TODO: We should throw here if you deleted the 'testPlan'. - $sync = array('title', 'summary', 'testPlan'); foreach ($sync as $field) { $local = $message->getFieldValue($field); @@ -460,45 +480,6 @@ EOTEXT $new_message = ArcanistDifferentialCommitMessage::newFromRawCorpus( $new_text); $new_message->pullDataFromConduit($conduit); -/* - TODO: restore these checks - - - try { // <<< this try goes right after the edit - - if (!$new_message->getTitle()) { - throw new UsageException( - "You can not remove the Revision title."); - } - if (!$new_message->getTestPlan()) { - throw new UsageException( - "You can not remove the 'Test Plan'."); - } - if ($new_message->getRevisionID() != $revision->getID()) { - throw new UsageException( - "You changed or deleted the Differential revision ID! Why ". - "would you do that?!"); - } - - } catch (Exception $ex) { - $ii = 0; - do { - $name = $ii - ? 'differential-message-'.$ii.'.txt' - : 'differential-message.txt'; - if (!file_exists($name)) { - break; - } - ++$ii; - } while(true); - require_module_lazy('resource/filesystem'); - Filesystem::writeFile($name, $new_text); - echo "Exception! Message was saved to '{$name}'.\n"; - throw $ex; - } -*/ - - $revision['fields'] = $new_message->getFields(); } @@ -1253,4 +1234,51 @@ EOTEXT return null; } + private function getCommitMessageFromUser() { + $conduit = $this->getConduit(); + + $template = $conduit->callMethodSynchronous( + 'differential.getcommitmessage', + array( + 'revision_id' => null, + 'edit' => true, + )); + + $template = + $template. + "\n\n". + "# Describe this revision.". + "\n"; + $template = id(new PhutilInteractiveEditor($template)) + ->setName('new-commit') + ->editInteractively(); + $template = preg_replace('/^\s*#.*$/m', '', $template); + + try { + $message = ArcanistDifferentialCommitMessage::newFromRawCorpus( + $template); + $message->pullDataFromConduit($conduit); + } catch (Exception $ex) { + $path = Filesystem::writeUniqueFile('arc-commit-message', $template); + + echo phutil_console_wrap( + "\n". + "Exception while parsing commit message! Message saved to ". + "'{$path}'. Use -F to specify a commit message file.\n"); + + throw $ex; + } + + return $message; + } + + private function getCommitMessageFromFile($file) { + $conduit = $this->getConduit(); + + $data = Filesystem::readFile($file); + $message = ArcanistDifferentialCommitMessage::newFromRawCorpus($data); + $message->pullDataFromConduit($conduit); + return $message; + } + } diff --git a/src/workflow/diff/__init__.php b/src/workflow/diff/__init__.php index c7dd37ca..64177eb6 100644 --- a/src/workflow/diff/__init__.php +++ b/src/workflow/diff/__init__.php @@ -19,6 +19,7 @@ phutil_require_module('arcanist', 'workflow/unit'); phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'console/editor'); +phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem/filelist'); phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'utils');