Presubmit: if there are warnings and may_prompt is false, don't fail.

Rationale: The description of the -f flag to git cl upload is "force
yes to questions (don't prompt)", so when git cl upload -f is run,
I would expect it to abort on errors, but still continue on warnings.

When the -f is given, DoPresubmitChecks is called with may_prompt=False;
this CL would change the behavior of DoPresubmitChecks so that when
may_prompt is False and there are warnings but no errors, then that
means we will print warnings but not fail.

BUG=671683

Change-Id: Ie0f1ac1983d875226db8ad741cbce3dc0bc4eb96
Reviewed-on: https://chromium-review.googlesource.com/419148
Reviewed-by: Aaron Gable <agable@chromium.org>
Commit-Queue: Quinten Yearsley <qyearsley@chromium.org>
changes/48/419148/5
Quinten Yearsley 8 years ago committed by Commit Bot
parent 9b713dd18b
commit 516fe7f881

@ -1174,7 +1174,6 @@ class PresubmitExecuter(object):
os.chdir(main_path)
return result
def DoPresubmitChecks(change,
committing,
verbose,
@ -1201,7 +1200,8 @@ def DoPresubmitChecks(change,
output_stream: A stream to write output from presubmit tests to.
input_stream: A stream to read input from the user.
default_presubmit: A default presubmit script to execute in any case.
may_prompt: Enable (y/n) questions on warning or error.
may_prompt: Enable (y/n) questions on warning or error. If False,
any questions are answered with yes by default.
rietveld_obj: rietveld.Rietveld object.
gerrit_obj: provides basic Gerrit codereview functionality.
dry_run: if true, some Checks will be skipped.
@ -1271,14 +1271,14 @@ def DoPresubmitChecks(change,
if total_time > 1.0:
output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time)
if not errors:
if not warnings:
output.write('Presubmit checks passed.\n')
elif may_prompt:
output.prompt_yes_no('There were presubmit warnings. '
'Are you sure you wish to continue? (y/N): ')
else:
output.fail()
if errors:
output.fail()
elif warnings:
output.write('There were presubmit warnings. ')
if may_prompt:
output.prompt_yes_no('Are you sure you wish to continue? (y/N): ')
else:
output.write('Presubmit checks passed.\n')
global _ASKED_FOR_FEEDBACK
# Ask for feedback one time out of 5.

@ -634,6 +634,38 @@ class PresubmitUnittest(PresubmitTestsBase):
self.assertEqual(output.getvalue().count(
'Running presubmit upload checks ...\n'), 1)
def testDoPresubmitChecksWithWarningsAndNoPrompt(self):
presubmit_path = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
haspresubmit_path = presubmit.os.path.join(
self.fake_root_dir, 'haspresubmit', 'PRESUBMIT.py')
inherit_path = presubmit.os.path.join(self.fake_root_dir,
self._INHERIT_SETTINGS)
presubmit.os.path.isfile(inherit_path).AndReturn(False)
presubmit.os.listdir(self.fake_root_dir).AndReturn(['PRESUBMIT.py'])
presubmit.os.path.isfile(presubmit_path).AndReturn(True)
presubmit.os.listdir(presubmit.os.path.join(
self.fake_root_dir, 'haspresubmit')).AndReturn(['PRESUBMIT.py'])
presubmit.os.path.isfile(haspresubmit_path).AndReturn(True)
presubmit.gclient_utils.FileRead(presubmit_path, 'rU').AndReturn(
self.presubmit_text)
presubmit.gclient_utils.FileRead(haspresubmit_path, 'rU').AndReturn(
self.presubmit_text)
presubmit.random.randint(0, 4).AndReturn(1)
self.mox.ReplayAll()
change = self.ExampleChange(extra_lines=['NOSUCHKEY=http://tracker/123'])
# There is no input buffer and may_prompt is set to False.
output = presubmit.DoPresubmitChecks(
change=change, committing=False, verbose=True,
output_stream=None, input_stream=None,
default_presubmit=None, may_prompt=False, rietveld_obj=None)
# A warning is printed, and should_continue is True.
self.failUnless(output.should_continue())
self.assertEquals(output.getvalue().count('??'), 2)
self.assertEqual(output.getvalue().count(
'Running presubmit upload checks ...\n'), 1)
def testDoPresubmitChecksNoWarningPromptIfErrors(self):
presubmit_path = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
haspresubmit_path = presubmit.os.path.join(

Loading…
Cancel
Save