| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 __version__ = '1.6.1' | 9 __version__ = '1.6.1' |
| 10 | 10 |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 files = [] | 1176 files = [] |
| 1177 for arg in args: | 1177 for arg in args: |
| 1178 files.extend([('M', f) for f in ScanSubDirs(arg, recursive)]) | 1178 files.extend([('M', f) for f in ScanSubDirs(arg, recursive)]) |
| 1179 return files | 1179 return files |
| 1180 | 1180 |
| 1181 | 1181 |
| 1182 def load_files(options, args): | 1182 def load_files(options, args): |
| 1183 """Tries to determine the SCM.""" | 1183 """Tries to determine the SCM.""" |
| 1184 change_scm = scm.determine_scm(options.root) | 1184 change_scm = scm.determine_scm(options.root) |
| 1185 files = [] | 1185 files = [] |
| 1186 if args: |
| 1187 files = ParseFiles(args, options.recursive) |
| 1186 if change_scm == 'svn': | 1188 if change_scm == 'svn': |
| 1187 change_class = SvnChange | 1189 change_class = SvnChange |
| 1188 status_fn = scm.SVN.CaptureStatus | 1190 if not files: |
| 1191 files = scm.SVN.CaptureStatus([], options.root) |
| 1189 elif change_scm == 'git': | 1192 elif change_scm == 'git': |
| 1190 change_class = GitChange | 1193 change_class = GitChange |
| 1191 status_fn = scm.GIT.CaptureStatus | 1194 # TODO(maruel): Get upstream. |
| 1195 if not files: |
| 1196 files = scm.GIT.CaptureStatus([], options.root, None) |
| 1192 else: | 1197 else: |
| 1193 logging.info('Doesn\'t seem under source control. Got %d files' % len(args)) | 1198 logging.info('Doesn\'t seem under source control. Got %d files' % len(args)) |
| 1194 if not args: | 1199 if not files: |
| 1195 return None, None | 1200 return None, None |
| 1196 change_class = Change | 1201 change_class = Change |
| 1197 if args: | |
| 1198 files = ParseFiles(args, options.recursive) | |
| 1199 else: | |
| 1200 # Grab modified files. | |
| 1201 files = status_fn([options.root]) | |
| 1202 return change_class, files | 1202 return change_class, files |
| 1203 | 1203 |
| 1204 | 1204 |
| 1205 def Main(argv): | 1205 def Main(argv): |
| 1206 parser = optparse.OptionParser(usage="%prog [options] <files...>", | 1206 parser = optparse.OptionParser(usage="%prog [options] <files...>", |
| 1207 version="%prog " + str(__version__)) | 1207 version="%prog " + str(__version__)) |
| 1208 parser.add_option("-c", "--commit", action="store_true", default=False, | 1208 parser.add_option("-c", "--commit", action="store_true", default=False, |
| 1209 help="Use commit instead of upload checks") | 1209 help="Use commit instead of upload checks") |
| 1210 parser.add_option("-u", "--upload", action="store_false", dest='commit', | 1210 parser.add_option("-u", "--upload", action="store_false", dest='commit', |
| 1211 help="Use upload instead of commit checks") | 1211 help="Use upload instead of commit checks") |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 except PresubmitFailure, e: | 1265 except PresubmitFailure, e: |
| 1266 print >> sys.stderr, e | 1266 print >> sys.stderr, e |
| 1267 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1267 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
| 1268 print >> sys.stderr, 'If all fails, contact maruel@' | 1268 print >> sys.stderr, 'If all fails, contact maruel@' |
| 1269 return 2 | 1269 return 2 |
| 1270 | 1270 |
| 1271 | 1271 |
| 1272 if __name__ == '__main__': | 1272 if __name__ == '__main__': |
| 1273 fix_encoding.fix_encoding() | 1273 fix_encoding.fix_encoding() |
| 1274 sys.exit(Main(None)) | 1274 sys.exit(Main(None)) |
| OLD | NEW |