| 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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 log_args = [args[0] + '..' + args[1]] | 919 log_args = [args[0] + '..' + args[1]] |
| 920 else: | 920 else: |
| 921 log_args = args[:] # Hope for the best! | 921 log_args = args[:] # Hope for the best! |
| 922 return RunGit(['log', '--pretty=format:%s\n\n%b'] + log_args) | 922 return RunGit(['log', '--pretty=format:%s\n\n%b'] + log_args) |
| 923 | 923 |
| 924 | 924 |
| 925 def CMDpresubmit(parser, args): | 925 def CMDpresubmit(parser, args): |
| 926 """run presubmit tests on the current changelist""" | 926 """run presubmit tests on the current changelist""" |
| 927 parser.add_option('--upload', action='store_true', | 927 parser.add_option('--upload', action='store_true', |
| 928 help='Run upload hook instead of the push/dcommit hook') | 928 help='Run upload hook instead of the push/dcommit hook') |
| 929 parser.add_option('--force', action='store_true', |
| 930 help='Run checks even if tree is dirty') |
| 929 (options, args) = parser.parse_args(args) | 931 (options, args) = parser.parse_args(args) |
| 930 | 932 |
| 931 # Make sure index is up-to-date before running diff-index. | 933 # Make sure index is up-to-date before running diff-index. |
| 932 RunGit(['update-index', '--refresh', '-q'], error_ok=True) | 934 RunGit(['update-index', '--refresh', '-q'], error_ok=True) |
| 933 if RunGit(['diff-index', 'HEAD']): | 935 if not options.force and RunGit(['diff-index', 'HEAD']): |
| 934 # TODO(maruel): Is this really necessary? | 936 # TODO(maruel): Is this really necessary? |
| 935 print 'Cannot presubmit with a dirty tree. You must commit locally first.' | 937 print ('Cannot presubmit with a dirty tree.\n' |
| 938 'You must commit locally first (or use --force).') |
| 936 return 1 | 939 return 1 |
| 937 | 940 |
| 938 cl = Changelist() | 941 cl = Changelist() |
| 939 if args: | 942 if args: |
| 940 base_branch = args[0] | 943 base_branch = args[0] |
| 941 else: | 944 else: |
| 942 # Default to diffing against the "upstream" branch. | 945 # Default to diffing against the "upstream" branch. |
| 943 base_branch = cl.GetUpstreamBranch() | 946 base_branch = cl.GetUpstreamBranch() |
| 944 | 947 |
| 945 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, | 948 cl.RunHook(committing=not options.upload, upstream_branch=base_branch, |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1610 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1613 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1611 | 1614 |
| 1612 # Not a known command. Default to help. | 1615 # Not a known command. Default to help. |
| 1613 GenUsage(parser, 'help') | 1616 GenUsage(parser, 'help') |
| 1614 return CMDhelp(parser, argv) | 1617 return CMDhelp(parser, argv) |
| 1615 | 1618 |
| 1616 | 1619 |
| 1617 if __name__ == '__main__': | 1620 if __name__ == '__main__': |
| 1618 fix_encoding.fix_encoding() | 1621 fix_encoding.fix_encoding() |
| 1619 sys.exit(main(sys.argv[1:])) | 1622 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |