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