Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: presubmit_canned_checks.py

Issue 155489: Add a presubmit check for accidental checkins of files under a SVN modified d... (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generic presubmit checks that can be reused by other presubmit checks.""" 6 """Generic presubmit checks that can be reused by other presubmit checks."""
7 7
8 8
9 ### Description checks 9 ### Description checks
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 cr_files = [] 81 cr_files = []
82 for f in input_api.AffectedSourceFiles(source_file_filter): 82 for f in input_api.AffectedSourceFiles(source_file_filter):
83 if '\r' in input_api.ReadFile(f, 'rb'): 83 if '\r' in input_api.ReadFile(f, 'rb'):
84 cr_files.append(f.LocalPath()) 84 cr_files.append(f.LocalPath())
85 if cr_files: 85 if cr_files:
86 return [output_api.PresubmitPromptWarning( 86 return [output_api.PresubmitPromptWarning(
87 "Found a CR character in these files:", items=cr_files)] 87 "Found a CR character in these files:", items=cr_files)]
88 return [] 88 return []
89 89
90 90
91 def CheckSvnModifiedDirectories(input_api, output_api, source_file_filter=None):
92 """Checks for files in svn modified directories.
93
94 They will get submitted on accident because svn commits recursively by
95 default, and that's very dangerous.
96 """
97 if input_api.change.scm != 'svn':
98 return []
99
100 errors = []
101 current_cl_files = input_api.change.GetModifiedFiles()
102 all_modified_files = input_api.change.GetAllModifiedFiles()
103 # Filter out files in the current CL.
104 modified_files = [f for f in all_modified_files if f not in current_cl_files]
105 modified_abspaths = [input_api.os_path.abspath(f) for f in modified_files]
106
107 for f in input_api.AffectedFiles(source_file_filter):
108 if f.Action() == 'M' and f.IsDirectory():
109 curpath = f.AbsoluteLocalPath()
110 bad_files = []
111 # Check if any of the modified files in other CLs are under curpath.
112 for i in xrange(len(modified_files)):
113 abspath = modified_abspaths[i]
114 if input_api.os_path.commonprefix([curpath, abspath]) == curpath:
115 bad_files.append(modified_files[i])
116 if bad_files:
117 if input_api.is_committing:
118 error_type = output_api.PresubmitPromptWarning
119 else:
120 error_type = output_api.PresubmitNotifyResult
121 errors.append(error_type(
122 "Potential accidental commits in changelist %s:" % f.LocalPath(),
123 items=bad_files))
124 return errors
125
126
91 def CheckChangeHasOnlyOneEol(input_api, output_api, source_file_filter=None): 127 def CheckChangeHasOnlyOneEol(input_api, output_api, source_file_filter=None):
92 """Checks the files ends with one and only one \n (LF).""" 128 """Checks the files ends with one and only one \n (LF)."""
93 eof_files = [] 129 eof_files = []
94 for f in input_api.AffectedSourceFiles(source_file_filter): 130 for f in input_api.AffectedSourceFiles(source_file_filter):
95 contents = input_api.ReadFile(f, 'rb') 131 contents = input_api.ReadFile(f, 'rb')
96 # Check that the file ends in one and only one newline character. 132 # Check that the file ends in one and only one newline character.
97 if len(contents) > 1 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"): 133 if len(contents) > 1 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"):
98 eof_files.append(f.LocalPath()) 134 eof_files.append(f.LocalPath())
99 135
100 if eof_files: 136 if eof_files:
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 RunCheck('image/bmp', FilterFiles(['.bmp'])) 249 RunCheck('image/bmp', FilterFiles(['.bmp']))
214 RunCheck('image/gif', FilterFiles(['.gif'])) 250 RunCheck('image/gif', FilterFiles(['.gif']))
215 RunCheck('image/png', FilterFiles(['.png'])) 251 RunCheck('image/png', FilterFiles(['.png']))
216 RunCheck('image/jpeg', FilterFiles(['.jpg', '.jpeg', '.jpe'])) 252 RunCheck('image/jpeg', FilterFiles(['.jpg', '.jpeg', '.jpe']))
217 RunCheck('image/vnd.microsoft.icon', FilterFiles(['.ico'])) 253 RunCheck('image/vnd.microsoft.icon', FilterFiles(['.ico']))
218 return output 254 return output
219 255
220 256
221 def CheckSvnProperty(input_api, output_api, prop, expected, affected_files): 257 def CheckSvnProperty(input_api, output_api, prop, expected, affected_files):
222 """Checks that affected_files files have prop=expected.""" 258 """Checks that affected_files files have prop=expected."""
223 bad = filter(lambda f: f.scm == 'svn' and f.Property(prop) != expected, 259 if input_api.change.scm != 'svn':
224 affected_files) 260 return []
261
262 bad = filter(lambda f: f.Property(prop) != expected, affected_files)
225 if bad: 263 if bad:
226 if input_api.is_committing: 264 if input_api.is_committing:
227 type = output_api.PresubmitError 265 type = output_api.PresubmitError
228 else: 266 else:
229 type = output_api.PresubmitNotifyResult 267 type = output_api.PresubmitNotifyResult
230 message = "Run `svn pset %s %s <item>` on these files:" % (prop, expected) 268 message = "Run `svn pset %s %s <item>` on these files:" % (prop, expected)
231 return [type(message, items=bad)] 269 return [type(message, items=bad)]
232 return [] 270 return []
233 271
234 272
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 stderr=input_api.subprocess.PIPE) 339 stderr=input_api.subprocess.PIPE)
302 stdoutdata, stderrdata = subproc.communicate() 340 stdoutdata, stderrdata = subproc.communicate()
303 # Discard the output if returncode == 0 341 # Discard the output if returncode == 0
304 if subproc.returncode: 342 if subproc.returncode:
305 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % ( 343 outputs.append("Test '%s' failed with code %d\n%s\n%s\n" % (
306 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) 344 unit_test_name, subproc.returncode, stdoutdata, stderrdata))
307 if outputs: 345 if outputs:
308 return [message_type("%d unit tests failed." % len(outputs), 346 return [message_type("%d unit tests failed." % len(outputs),
309 long_text='\n'.join(outputs))] 347 long_text='\n'.join(outputs))]
310 return [] 348 return []
OLDNEW
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698