| 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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   992 def CMDpresubmit(parser, args): |   992 def CMDpresubmit(parser, args): | 
|   993   """run presubmit tests on the current changelist""" |   993   """run presubmit tests on the current changelist""" | 
|   994   parser.add_option('--upload', action='store_true', |   994   parser.add_option('--upload', action='store_true', | 
|   995                     help='Run upload hook instead of the push/dcommit hook') |   995                     help='Run upload hook instead of the push/dcommit hook') | 
|   996   parser.add_option('--force', action='store_true', |   996   parser.add_option('--force', action='store_true', | 
|   997                     help='Run checks even if tree is dirty') |   997                     help='Run checks even if tree is dirty') | 
|   998   (options, args) = parser.parse_args(args) |   998   (options, args) = parser.parse_args(args) | 
|   999  |   999  | 
|  1000   # Make sure index is up-to-date before running diff-index. |  1000   # Make sure index is up-to-date before running diff-index. | 
|  1001   RunGit(['update-index', '--refresh', '-q'], error_ok=True) |  1001   RunGit(['update-index', '--refresh', '-q'], error_ok=True) | 
|  1002   if not options.force and RunGit(['diff-index', 'HEAD']): |  1002   diff_index = RunGit(['diff-index', 'HEAD']) | 
 |  1003   if not options.force and diff_index: | 
|  1003     # TODO(maruel): Is this really necessary? |  1004     # TODO(maruel): Is this really necessary? | 
|  1004     print ('Cannot presubmit with a dirty tree.\n' |  1005     print >> sys.stderr, ( | 
|  1005           'You must commit locally first (or use --force).') |  1006         'Cannot presubmit with a dirty tree.\n' | 
 |  1007         'You must commit locally first (or use --force).\n' | 
 |  1008         'git diff-index HEAD\n%s' % diff_index[:4096]) | 
|  1006     return 1 |  1009     return 1 | 
|  1007  |  1010  | 
|  1008   cl = Changelist() |  1011   cl = Changelist() | 
|  1009   if args: |  1012   if args: | 
|  1010     base_branch = args[0] |  1013     base_branch = args[0] | 
|  1011   else: |  1014   else: | 
|  1012     # Default to diffing against the "upstream" branch. |  1015     # Default to diffing against the "upstream" branch. | 
|  1013     base_branch = cl.GetUpstreamBranch() |  1016     base_branch = cl.GetUpstreamBranch() | 
|  1014  |  1017  | 
|  1015   cl.RunHook(committing=not options.upload, upstream_branch=base_branch, |  1018   cl.RunHook(committing=not options.upload, upstream_branch=base_branch, | 
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1194   # Print warning if the user used the -m/--message argument.  This will soon |  1197   # Print warning if the user used the -m/--message argument.  This will soon | 
|  1195   # change to -t/--title. |  1198   # change to -t/--title. | 
|  1196   if options.message: |  1199   if options.message: | 
|  1197     print >> sys.stderr, ( |  1200     print >> sys.stderr, ( | 
|  1198         '\nWARNING: Use -t or --title to set the title of the patchset.\n' |  1201         '\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' |  1202         'In the near future, -m or --message will send a message instead.\n' | 
|  1200         'See http://goo.gl/JGg0Z for details.\n') |  1203         'See http://goo.gl/JGg0Z for details.\n') | 
|  1201  |  1204  | 
|  1202   # Make sure index is up-to-date before running diff-index. |  1205   # Make sure index is up-to-date before running diff-index. | 
|  1203   RunGit(['update-index', '--refresh', '-q'], error_ok=True) |  1206   RunGit(['update-index', '--refresh', '-q'], error_ok=True) | 
|  1204   if RunGit(['diff-index', 'HEAD']): |  1207   diff_index = RunGit(['diff-index', 'HEAD']) | 
|  1205     print 'Cannot upload with a dirty tree.  You must commit locally first.' |  1208   if diff_index: | 
 |  1209     print >> sys.stderr, ( | 
 |  1210         'Cannot upload with a dirty tree.  You must commit locally first.' | 
 |  1211         'git diff-index HEAD\n%s' % diff_index[:4096]) | 
|  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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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   # Make sure index is up-to-date before running diff-index. | 
|  1276   RunGit(['update-index', '--refresh', '-q'], error_ok=True) |  1282   RunGit(['update-index', '--refresh', '-q'], error_ok=True) | 
|  1277   if RunGit(['diff-index', 'HEAD']): |  1283   diff_index = RunGit(['diff-index', 'HEAD']) | 
|  1278     print 'Cannot %s with a dirty tree.  You must commit locally first.' % cmd |  1284   if diff_index: | 
 |  1285     print >> sys.stderr, ( | 
 |  1286         'Cannot %s with a dirty tree.  You must commit locally first.' | 
 |  1287         'git diff-index HEAD\n%s' % (cmd, diff_index[:4096])) | 
|  1279     return 1 |  1288     return 1 | 
|  1280  |  1289  | 
|  1281   # This rev-list syntax means "show all commits not in my branch that |  1290   # This rev-list syntax means "show all commits not in my branch that | 
|  1282   # are in base_branch". |  1291   # are in base_branch". | 
|  1283   upstream_commits = RunGit(['rev-list', '^' + cl.GetBranchRef(), |  1292   upstream_commits = RunGit(['rev-list', '^' + cl.GetBranchRef(), | 
|  1284                              base_branch]).splitlines() |  1293                              base_branch]).splitlines() | 
|  1285   if upstream_commits: |  1294   if upstream_commits: | 
|  1286     print ('Base branch "%s" has %d commits ' |  1295     print ('Base branch "%s" has %d commits ' | 
|  1287            'not in this branch.' % (base_branch, len(upstream_commits))) |  1296            'not in this branch.' % (base_branch, len(upstream_commits))) | 
|  1288     print 'Run "git merge %s" before attempting to %s.' % (base_branch, cmd) |  1297     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))) |  1815              'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 
|  1807  |  1816  | 
|  1808   # Not a known command. Default to help. |  1817   # Not a known command. Default to help. | 
|  1809   GenUsage(parser, 'help') |  1818   GenUsage(parser, 'help') | 
|  1810   return CMDhelp(parser, argv) |  1819   return CMDhelp(parser, argv) | 
|  1811  |  1820  | 
|  1812  |  1821  | 
|  1813 if __name__ == '__main__': |  1822 if __name__ == '__main__': | 
|  1814   fix_encoding.fix_encoding() |  1823   fix_encoding.fix_encoding() | 
|  1815   sys.exit(main(sys.argv[1:])) |  1824   sys.exit(main(sys.argv[1:])) | 
| OLD | NEW |