From 9e77d3b3bacaaf9b8b65bf286b974ec77f385b08 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 10 Jan 2011 14:03:12 -0800 Subject: [PATCH] Add --never-apply-patches and --apply-patches to lint. Summary: These flags let you force the behavior of 'arc lint' instead of prompting. Also made the amend behavior default to false since I've screwed this up about 300 times in the mere hours I've been using git as a primary VCS. Test Plan: ran arc lint with these flags Reviewers: CC: --- src/workflow/diff/ArcanistDiffWorkflow.php | 24 +++++++++++ src/workflow/lint/ArcanistLintWorkflow.php | 47 +++++++++++++++++----- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/workflow/diff/ArcanistDiffWorkflow.php b/src/workflow/diff/ArcanistDiffWorkflow.php index 17023a26..b9e1e151 100644 --- a/src/workflow/diff/ArcanistDiffWorkflow.php +++ b/src/workflow/diff/ArcanistDiffWorkflow.php @@ -90,6 +90,8 @@ EOTEXT 'conflicts' => array( 'lintall' => '--nolint suppresses lint.', 'advice' => '--nolint suppresses lint.', + 'apply-patches' => '--nolint suppresses lint.', + 'never-apply-patches' => '--nolint suppresses lint.', ), ), 'only' => array( @@ -102,6 +104,8 @@ EOTEXT 'edit' => '--only does not affect revisions.', 'lintall' => '--only suppresses lint.', 'advice' => '--only suppresses lint.', + 'apply-patches' => '--only suppresses lint.', + 'never-apply-patches' => '--only suppresses lint.', 'nounit' => '--only implies --nounit.', 'nolint' => '--only implies --nolint.', ), @@ -143,6 +147,20 @@ EOTEXT 'help' => "Raise lint advice in addition to lint warnings and errors.", ), + 'apply-patches' => array( + 'help' => + 'Apply patches suggested by lint to the working copy without '. + 'prompting.', + 'conflicts' => array( + 'never-apply-patches' => true, + ), + ), + 'never-apply-patches' => array( + 'help' => 'Never apply patches suggested by lint.', + 'conflicts' => array( + 'apply-patches' => true, + ), + ), '*' => 'paths', ); } @@ -696,6 +714,12 @@ EOTEXT if ($this->getArgument('advice')) { $argv[] = '--advice'; } + if ($this->getArgument('apply-patches')) { + $argv[] = '--apply-patches'; + } + if ($this->getArgument('never-apply-patches')) { + $argv[] = '--never-apply-patches'; + } if ($repository_api instanceof ArcanistSubversionAPI) { $argv = array_merge($argv, array_keys($paths)); } else { diff --git a/src/workflow/lint/ArcanistLintWorkflow.php b/src/workflow/lint/ArcanistLintWorkflow.php index e32d3426..9b2d276e 100644 --- a/src/workflow/lint/ArcanistLintWorkflow.php +++ b/src/workflow/lint/ArcanistLintWorkflow.php @@ -53,6 +53,20 @@ EOTEXT 'help' => "Override configured lint engine for this project." ), + 'apply-patches' => array( + 'help' => + 'Apply patches suggested by lint to the working copy without '. + 'prompting.', + 'conflicts' => array( + 'never-apply-patches' => true, + ), + ), + 'never-apply-patches' => array( + 'help' => 'Never apply patches suggested by lint.', + 'conflicts' => array( + 'apply-patches' => true, + ), + ), '*' => 'paths', ); } @@ -146,8 +160,18 @@ EOTEXT $results = $engine->run(); - $apply_patches = true; - $prompt_patches = true; + if ($this->getArgument('never-apply-patches')) { + $apply_patches = false; + } else { + $apply_patches = true; + } + + if ($this->getArgument('apply-patches')) { + $prompt_patches = false; + } else { + $prompt_patches = true; + } + $wrote_to_disk = false; $renderer = new ArcanistLintRenderer(); @@ -192,15 +216,18 @@ EOTEXT } if ($wrote_to_disk && ($repository_api instanceof ArcanistGitAPI)) { - $amend = phutil_console_confirm( - "Amend HEAD with lint patches?", - $default_no = false); - if (!$amend) { - throw new ArcanistUsageException("Resolve lint changes and relint."); + $amend = phutil_console_confirm("Amend HEAD with lint patches?"); + if ($amend) { + execx( + '(cd %s; git commit -a --amend -C HEAD)', + $repository_api->getPath()); + } else { + if ($this->getParentWorkflow()) { + throw new ArcanistUsageException( + "Sort out the lint changes that were applied to the working ". + "copy and relint."); + } } - execx( - '(cd %s; git commit -a --amend -C HEAD)', - $repository_api->getPath()); } $result_code = self::RESULT_OKAY;