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

Side by Side Diff: presubmit_support.py

Issue 6459010: Improve presubmit_support.py handling of git checkout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 10 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 | 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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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.3.5' 9 __version__ = '1.3.5'
10 10
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 dirs.remove('.svn') 1046 dirs.remove('.svn')
1047 if '.git' in dirs: 1047 if '.git' in dirs:
1048 dirs.remove('.git') 1048 dirs.remove('.git')
1049 for name in files: 1049 for name in files:
1050 if fnmatch.fnmatch(name, mask): 1050 if fnmatch.fnmatch(name, mask):
1051 results.append(os.path.join(root, name)) 1051 results.append(os.path.join(root, name))
1052 return results 1052 return results
1053 1053
1054 1054
1055 def ParseFiles(args, recursive): 1055 def ParseFiles(args, recursive):
1056 logging.debug('Searching for %s' % args)
1056 files = [] 1057 files = []
1057 for arg in args: 1058 for arg in args:
1058 files.extend([('M', f) for f in ScanSubDirs(arg, recursive)]) 1059 files.extend([('M', f) for f in ScanSubDirs(arg, recursive)])
1059 return files 1060 return files
1060 1061
1061 1062
1062 def Main(argv): 1063 def Main(argv):
1063 parser = optparse.OptionParser(usage="%prog [options]", 1064 parser = optparse.OptionParser(usage="%prog [options]",
1064 version="%prog " + str(__version__)) 1065 version="%prog " + str(__version__))
1065 parser.add_option("-c", "--commit", action="store_true", default=False, 1066 parser.add_option("-c", "--commit", action="store_true", default=False,
(...skipping 10 matching lines...) Expand all
1076 parser.add_option("--issue", type='int', default=0) 1077 parser.add_option("--issue", type='int', default=0)
1077 parser.add_option("--patchset", type='int', default=0) 1078 parser.add_option("--patchset", type='int', default=0)
1078 parser.add_option("--root", default=os.getcwd(), 1079 parser.add_option("--root", default=os.getcwd(),
1079 help="Search for PRESUBMIT.py up to this directory. " 1080 help="Search for PRESUBMIT.py up to this directory. "
1080 "If inherit-review-settings-ok is present in this " 1081 "If inherit-review-settings-ok is present in this "
1081 "directory, parent directories up to the root file " 1082 "directory, parent directories up to the root file "
1082 "system directories will also be searched.") 1083 "system directories will also be searched.")
1083 parser.add_option("--default_presubmit") 1084 parser.add_option("--default_presubmit")
1084 parser.add_option("--may_prompt", action='store_true', default=False) 1085 parser.add_option("--may_prompt", action='store_true', default=False)
1085 options, args = parser.parse_args(argv[1:]) 1086 options, args = parser.parse_args(argv[1:])
1086 if os.path.isdir(os.path.join(options.root, '.git')): 1087 if options.verbose:
1087 change_class = GitChange 1088 logging.basicConfig(level=logging.DEBUG)
1088 if not options.files: 1089 if os.path.isdir(os.path.join(options.root, '.svn')):
1089 if args:
1090 options.files = ParseFiles(args, options.recursive)
1091 else:
1092 # Grab modified files.
1093 options.files = scm.GIT.CaptureStatus([options.root])
1094 elif os.path.isdir(os.path.join(options.root, '.svn')):
1095 change_class = SvnChange 1090 change_class = SvnChange
1096 if not options.files: 1091 if not options.files:
1097 if args: 1092 if args:
1098 options.files = ParseFiles(args, options.recursive) 1093 options.files = ParseFiles(args, options.recursive)
1099 else: 1094 else:
1100 # Grab modified files. 1095 # Grab modified files.
1101 options.files = scm.SVN.CaptureStatus([options.root]) 1096 options.files = scm.SVN.CaptureStatus([options.root])
1102 else: 1097 else:
1103 # Doesn't seem under source control. 1098 is_git = os.path.isdir(os.path.join(options.root, '.git'))
1104 change_class = Change 1099 if not is_git:
1100 is_git = (0 == subprocess.call(
1101 ['git', 'rev-parse', '--show-cdup'],
1102 stdout=subprocess.PIPE, cwd=options.root))
1103 if is_git:
1104 # Only look at the subdirectories below cwd.
1105 change_class = GitChange
1106 if not options.files:
1107 if args:
1108 options.files = ParseFiles(args, options.recursive)
1109 else:
1110 # Grab modified files.
1111 options.files = scm.GIT.CaptureStatus([options.root])
1112 else:
1113 logging.info('Doesn\'t seem under source control.')
1114 change_class = Change
1105 if options.verbose: 1115 if options.verbose:
1106 if len(options.files) != 1: 1116 if not options.files:
1117 print "Found no files."
1118 elif len(options.files) != 1:
1107 print "Found %d files." % len(options.files) 1119 print "Found %d files." % len(options.files)
1108 else: 1120 else:
1109 print "Found 1 file." 1121 print "Found 1 file."
1110 return not DoPresubmitChecks(change_class(options.name, 1122 return not DoPresubmitChecks(change_class(options.name,
1111 options.description, 1123 options.description,
1112 options.root, 1124 options.root,
1113 options.files, 1125 options.files,
1114 options.issue, 1126 options.issue,
1115 options.patchset), 1127 options.patchset),
1116 options.commit, 1128 options.commit,
1117 options.verbose, 1129 options.verbose,
1118 sys.stdout, 1130 sys.stdout,
1119 sys.stdin, 1131 sys.stdin,
1120 options.default_presubmit, 1132 options.default_presubmit,
1121 options.may_prompt) 1133 options.may_prompt)
1122 1134
1123 1135
1124 if __name__ == '__main__': 1136 if __name__ == '__main__':
1125 sys.exit(Main(sys.argv)) 1137 sys.exit(Main(sys.argv))
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