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 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
7 | 7 |
8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 import json | 10 import json |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 else: | 143 else: |
144 git_set_branch_value('git-find-copies', int(options.find_copies)) | 144 git_set_branch_value('git-find-copies', int(options.find_copies)) |
145 | 145 |
146 print('Using %d%% similarity for rename/copy detection. ' | 146 print('Using %d%% similarity for rename/copy detection. ' |
147 'Override with --similarity.' % options.similarity) | 147 'Override with --similarity.' % options.similarity) |
148 | 148 |
149 return options, args | 149 return options, args |
150 parser.parse_args = Parse | 150 parser.parse_args = Parse |
151 | 151 |
152 | 152 |
153 def is_dirty_git_tree(cmd): | |
154 # Make sure index is up-to-date before running diff-index. | |
155 RunGit(['update-index', '--refresh', '-q'], error_ok=True) | |
156 dirty = RunGit(['diff-index', '--name-status', 'HEAD']) | |
157 if dirty: | |
158 print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd | |
159 print 'Uncommitted files: (git diff-index --name-status HEAD)' | |
160 print dirty[:4096] | |
Isaac (away)
2012/10/25 07:53:20
actually 4096 is pretty long. Maybe we want shorte
| |
161 if len(dirty) > 4096: | |
162 print '... (run "git diff-index --name-status HEAD" to see full output).' | |
163 return True | |
164 return False | |
165 | |
153 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): | 166 def MatchSvnGlob(url, base_url, glob_spec, allow_wildcards): |
154 """Return the corresponding git ref if |base_url| together with |glob_spec| | 167 """Return the corresponding git ref if |base_url| together with |glob_spec| |
155 matches the full |url|. | 168 matches the full |url|. |
156 | 169 |
157 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). | 170 If |allow_wildcards| is true, |glob_spec| can contain wildcards (see below). |
158 """ | 171 """ |
159 fetch_suburl, as_ref = glob_spec.split(':') | 172 fetch_suburl, as_ref = glob_spec.split(':') |
160 if allow_wildcards: | 173 if allow_wildcards: |
161 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl) | 174 glob_match = re.match('(.+/)?(\*|{[^/]*})(/.+)?', fetch_suburl) |
162 if glob_match: | 175 if glob_match: |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 | 1003 |
991 | 1004 |
992 def CMDpresubmit(parser, args): | 1005 def CMDpresubmit(parser, args): |
993 """run presubmit tests on the current changelist""" | 1006 """run presubmit tests on the current changelist""" |
994 parser.add_option('--upload', action='store_true', | 1007 parser.add_option('--upload', action='store_true', |
995 help='Run upload hook instead of the push/dcommit hook') | 1008 help='Run upload hook instead of the push/dcommit hook') |
996 parser.add_option('--force', action='store_true', | 1009 parser.add_option('--force', action='store_true', |
997 help='Run checks even if tree is dirty') | 1010 help='Run checks even if tree is dirty') |
998 (options, args) = parser.parse_args(args) | 1011 (options, args) = parser.parse_args(args) |
999 | 1012 |
1000 # Make sure index is up-to-date before running diff-index. | 1013 if not options.force and is_dirty_git_tree('presubmit'): |
1001 RunGit(['update-index', '--refresh', '-q'], error_ok=True) | 1014 print 'use --force to check even if tree is dirty.' |
1002 if not options.force and RunGit(['diff-index', 'HEAD']): | |
1003 # TODO(maruel): Is this really necessary? | |
1004 print ('Cannot presubmit with a dirty tree.\n' | |
1005 'You must commit locally first (or use --force).') | |
1006 return 1 | 1015 return 1 |
1007 | 1016 |
1008 cl = Changelist() | 1017 cl = Changelist() |
1009 if args: | 1018 if args: |
1010 base_branch = args[0] | 1019 base_branch = args[0] |
1011 else: | 1020 else: |
1012 # Default to diffing against the "upstream" branch. | 1021 # Default to diffing against the "upstream" branch. |
1013 base_branch = cl.GetUpstreamBranch() | 1022 base_branch = cl.GetUpstreamBranch() |
1014 | 1023 |
1015 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, | 1024 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 (options, args) = parser.parse_args(args) | 1201 (options, args) = parser.parse_args(args) |
1193 | 1202 |
1194 # Print warning if the user used the -m/--message argument. This will soon | 1203 # Print warning if the user used the -m/--message argument. This will soon |
1195 # change to -t/--title. | 1204 # change to -t/--title. |
1196 if options.message: | 1205 if options.message: |
1197 print >> sys.stderr, ( | 1206 print >> sys.stderr, ( |
1198 '\nWARNING: Use -t or --title to set the title of the patchset.\n' | 1207 '\nWARNING: Use -t or --title to set the title of the patchset.\n' |
1199 'In the near future, -m or --message will send a message instead.\n' | 1208 'In the near future, -m or --message will send a message instead.\n' |
1200 'See http://goo.gl/JGg0Z for details.\n') | 1209 'See http://goo.gl/JGg0Z for details.\n') |
1201 | 1210 |
1202 # Make sure index is up-to-date before running diff-index. | 1211 if is_dirty_git_tree('upload'): |
1203 RunGit(['update-index', '--refresh', '-q'], error_ok=True) | |
1204 if RunGit(['diff-index', 'HEAD']): | |
1205 print 'Cannot upload with a dirty tree. You must commit locally first.' | |
1206 return 1 | 1212 return 1 |
1207 | 1213 |
1208 cl = Changelist() | 1214 cl = Changelist() |
1209 if args: | 1215 if args: |
1210 # TODO(ukai): is it ok for gerrit case? | 1216 # TODO(ukai): is it ok for gerrit case? |
1211 base_branch = args[0] | 1217 base_branch = args[0] |
1212 else: | 1218 else: |
1213 # Default to diffing against the "upstream" branch. | 1219 # Default to diffing against the "upstream" branch. |
1214 base_branch = cl.GetUpstreamBranch() | 1220 base_branch = cl.GetUpstreamBranch() |
1215 args = [base_branch + "..."] | 1221 args = [base_branch + "..."] |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1265 args = [cl.GetUpstreamBranch()] | 1271 args = [cl.GetUpstreamBranch()] |
1266 | 1272 |
1267 if options.contributor: | 1273 if options.contributor: |
1268 if not re.match('^.*\s<\S+@\S+>$', options.contributor): | 1274 if not re.match('^.*\s<\S+@\S+>$', options.contributor): |
1269 print "Please provide contibutor as 'First Last <email@example.com>'" | 1275 print "Please provide contibutor as 'First Last <email@example.com>'" |
1270 return 1 | 1276 return 1 |
1271 | 1277 |
1272 base_branch = args[0] | 1278 base_branch = args[0] |
1273 base_has_submodules = IsSubmoduleMergeCommit(base_branch) | 1279 base_has_submodules = IsSubmoduleMergeCommit(base_branch) |
1274 | 1280 |
1275 # Make sure index is up-to-date before running diff-index. | 1281 if is_dirty_git_tree(cmd): |
1276 RunGit(['update-index', '--refresh', '-q'], error_ok=True) | |
1277 if RunGit(['diff-index', 'HEAD']): | |
1278 print 'Cannot %s with a dirty tree. You must commit locally first.' % cmd | |
1279 return 1 | 1282 return 1 |
1280 | 1283 |
1281 # This rev-list syntax means "show all commits not in my branch that | 1284 # This rev-list syntax means "show all commits not in my branch that |
1282 # are in base_branch". | 1285 # are in base_branch". |
1283 upstream_commits = RunGit(['rev-list', '^' + cl.GetBranchRef(), | 1286 upstream_commits = RunGit(['rev-list', '^' + cl.GetBranchRef(), |
1284 base_branch]).splitlines() | 1287 base_branch]).splitlines() |
1285 if upstream_commits: | 1288 if upstream_commits: |
1286 print ('Base branch "%s" has %d commits ' | 1289 print ('Base branch "%s" has %d commits ' |
1287 'not in this branch.' % (base_branch, len(upstream_commits))) | 1290 'not in this branch.' % (base_branch, len(upstream_commits))) |
1288 print 'Run "git merge %s" before attempting to %s.' % (base_branch, cmd) | 1291 print 'Run "git merge %s" before attempting to %s.' % (base_branch, cmd) |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1806 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1809 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1807 | 1810 |
1808 # Not a known command. Default to help. | 1811 # Not a known command. Default to help. |
1809 GenUsage(parser, 'help') | 1812 GenUsage(parser, 'help') |
1810 return CMDhelp(parser, argv) | 1813 return CMDhelp(parser, argv) |
1811 | 1814 |
1812 | 1815 |
1813 if __name__ == '__main__': | 1816 if __name__ == '__main__': |
1814 fix_encoding.fix_encoding() | 1817 fix_encoding.fix_encoding() |
1815 sys.exit(main(sys.argv[1:])) | 1818 sys.exit(main(sys.argv[1:])) |
OLD | NEW |