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

Side by Side Diff: presubmit_canned_checks.py

Issue 1435333005: Remove unused CheckSvnModifiedDirectories. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | tests/presubmit_unittest.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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 # Justifications for each filter: 10 # Justifications for each filter:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 cr_files = [] 154 cr_files = []
155 for f in input_api.AffectedSourceFiles(source_file_filter): 155 for f in input_api.AffectedSourceFiles(source_file_filter):
156 if '\r' in input_api.ReadFile(f, 'rb'): 156 if '\r' in input_api.ReadFile(f, 'rb'):
157 cr_files.append(f.LocalPath()) 157 cr_files.append(f.LocalPath())
158 if cr_files: 158 if cr_files:
159 return [output_api.PresubmitPromptWarning( 159 return [output_api.PresubmitPromptWarning(
160 'Found a CR character in these files:', items=cr_files)] 160 'Found a CR character in these files:', items=cr_files)]
161 return [] 161 return []
162 162
163 163
164 def CheckSvnModifiedDirectories(input_api, output_api, source_file_filter=None):
165 """Checks for files in svn modified directories.
166
167 They will get submitted on accident because svn commits recursively by
168 default, and that's very dangerous.
169 """
170 if input_api.change.scm != 'svn':
171 return []
172
173 errors = []
174 current_cl_files = input_api.change.GetModifiedFiles()
175 all_modified_files = input_api.change.GetAllModifiedFiles()
176 # Filter out files in the current CL.
177 modified_files = [f for f in all_modified_files if f not in current_cl_files]
178 modified_abspaths = [input_api.os_path.abspath(f) for f in modified_files]
179
180 for f in input_api.AffectedFiles(file_filter=source_file_filter):
181 if f.Action() == 'M' and f.IsDirectory():
182 curpath = f.AbsoluteLocalPath()
183 bad_files = []
184 # Check if any of the modified files in other CLs are under curpath.
185 for i in xrange(len(modified_files)):
186 abspath = modified_abspaths[i]
187 if input_api.os_path.commonprefix([curpath, abspath]) == curpath:
188 bad_files.append(modified_files[i])
189 if bad_files:
190 if input_api.is_committing:
191 error_type = output_api.PresubmitPromptWarning
192 else:
193 error_type = output_api.PresubmitNotifyResult
194 errors.append(error_type(
195 'Potential accidental commits in changelist %s:' % f.LocalPath(),
196 items=bad_files))
197 return errors
198
199
200 def CheckChangeHasOnlyOneEol(input_api, output_api, source_file_filter=None): 164 def CheckChangeHasOnlyOneEol(input_api, output_api, source_file_filter=None):
201 """Checks the files ends with one and only one \n (LF).""" 165 """Checks the files ends with one and only one \n (LF)."""
202 eof_files = [] 166 eof_files = []
203 for f in input_api.AffectedSourceFiles(source_file_filter): 167 for f in input_api.AffectedSourceFiles(source_file_filter):
204 contents = input_api.ReadFile(f, 'rb') 168 contents = input_api.ReadFile(f, 'rb')
205 # Check that the file ends in one and only one newline character. 169 # Check that the file ends in one and only one newline character.
206 if len(contents) > 1 and (contents[-1:] != '\n' or contents[-2:-1] == '\n'): 170 if len(contents) > 1 and (contents[-1:] != '\n' or contents[-2:-1] == '\n'):
207 eof_files.append(f.LocalPath()) 171 eof_files.append(f.LocalPath())
208 172
209 if eof_files: 173 if eof_files:
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 for f in affected_files: 1122 for f in affected_files:
1159 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] 1123 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
1160 rc = gn.main(cmd) 1124 rc = gn.main(cmd)
1161 if rc == 2: 1125 if rc == 2:
1162 warnings.append(output_api.PresubmitPromptWarning( 1126 warnings.append(output_api.PresubmitPromptWarning(
1163 '%s requires formatting. Please run `gn format --in-place %s`.' % ( 1127 '%s requires formatting. Please run `gn format --in-place %s`.' % (
1164 f.AbsoluteLocalPath(), f.LocalPath()))) 1128 f.AbsoluteLocalPath(), f.LocalPath())))
1165 # It's just a warning, so ignore other types of failures assuming they'll be 1129 # It's just a warning, so ignore other types of failures assuming they'll be
1166 # caught elsewhere. 1130 # caught elsewhere.
1167 return warnings 1131 return warnings
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698