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 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1686 | 1686 |
1687 @usage('<patch url or issue id>') | 1687 @usage('<patch url or issue id>') |
1688 def CMDpatch(parser, args): | 1688 def CMDpatch(parser, args): |
1689 """patch in a code review""" | 1689 """patch in a code review""" |
1690 parser.add_option('-b', dest='newbranch', | 1690 parser.add_option('-b', dest='newbranch', |
1691 help='create a new branch off trunk for the patch') | 1691 help='create a new branch off trunk for the patch') |
1692 parser.add_option('-f', action='store_true', dest='force', | 1692 parser.add_option('-f', action='store_true', dest='force', |
1693 help='with -b, clobber any existing branch') | 1693 help='with -b, clobber any existing branch') |
1694 parser.add_option('--reject', action='store_true', dest='reject', | 1694 parser.add_option('--reject', action='store_true', dest='reject', |
1695 help='allow failed patches and spew .rej files') | 1695 help='allow failed patches and spew .rej files') |
1696 parser.add_option('-3', '--3way', action='store_true', dest='three_way', | |
1697 help='allow failed patches to fall back on 3-way merge, ' | |
1698 'possibly leaving conflict markers to resolve') | |
1696 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', | 1699 parser.add_option('-n', '--no-commit', action='store_true', dest='nocommit', |
1697 help="don't commit after patch applies") | 1700 help="don't commit after patch applies") |
1698 (options, args) = parser.parse_args(args) | 1701 (options, args) = parser.parse_args(args) |
1699 if len(args) != 1: | 1702 if len(args) != 1: |
1700 parser.print_help() | 1703 parser.print_help() |
1701 return 1 | 1704 return 1 |
1702 issue_arg = args[0] | 1705 issue_arg = args[0] |
1703 | 1706 |
1704 # TODO(maruel): Use apply_issue.py | 1707 # TODO(maruel): Use apply_issue.py |
1705 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? | 1708 # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1743 ['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'], stdin=patch_data) | 1746 ['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'], stdin=patch_data) |
1744 except subprocess2.CalledProcessError: | 1747 except subprocess2.CalledProcessError: |
1745 DieWithError('Git patch mungling failed.') | 1748 DieWithError('Git patch mungling failed.') |
1746 logging.info(patch_data) | 1749 logging.info(patch_data) |
1747 # We use "git apply" to apply the patch instead of "patch" so that we can | 1750 # We use "git apply" to apply the patch instead of "patch" so that we can |
1748 # pick up file adds. | 1751 # pick up file adds. |
1749 # The --index flag means: also insert into the index (so we catch adds). | 1752 # The --index flag means: also insert into the index (so we catch adds). |
1750 cmd = ['git', '--no-pager', 'apply', '--index', '-p0'] | 1753 cmd = ['git', '--no-pager', 'apply', '--index', '-p0'] |
1751 if options.reject: | 1754 if options.reject: |
1752 cmd.append('--reject') | 1755 cmd.append('--reject') |
1756 elif options.three_way: | |
M-A Ruel
2013/06/05 18:47:34
I'm fine with adding it as the default without an
| |
1757 cmd.append('--3way') | |
1753 try: | 1758 try: |
1754 subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID) | 1759 subprocess2.check_call(cmd, stdin=patch_data, stdout=subprocess2.VOID) |
1755 except subprocess2.CalledProcessError: | 1760 except subprocess2.CalledProcessError: |
1756 DieWithError('Failed to apply the patch') | 1761 DieWithError('Failed to apply the patch') |
1757 | 1762 |
1758 # If we had an issue, commit the current state and register the issue. | 1763 # If we had an issue, commit the current state and register the issue. |
1759 if not options.nocommit: | 1764 if not options.nocommit: |
1760 RunGit(['commit', '-m', 'patch from issue %s' % issue]) | 1765 RunGit(['commit', '-m', 'patch from issue %s' % issue]) |
1761 cl = Changelist() | 1766 cl = Changelist() |
1762 cl.SetIssue(issue) | 1767 cl.SetIssue(issue) |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2093 GenUsage(parser, 'help') | 2098 GenUsage(parser, 'help') |
2094 return CMDhelp(parser, argv) | 2099 return CMDhelp(parser, argv) |
2095 | 2100 |
2096 | 2101 |
2097 if __name__ == '__main__': | 2102 if __name__ == '__main__': |
2098 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2103 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2099 # unit testing. | 2104 # unit testing. |
2100 fix_encoding.fix_encoding() | 2105 fix_encoding.fix_encoding() |
2101 colorama.init() | 2106 colorama.init() |
2102 sys.exit(main(sys.argv[1:])) | 2107 sys.exit(main(sys.argv[1:])) |
OLD | NEW |