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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1742 if settings.GetIsGitSvn(): | 1742 if settings.GetIsGitSvn(): |
1743 remote_url = cl.GetGitSvnRemoteUrl() | 1743 remote_url = cl.GetGitSvnRemoteUrl() |
1744 else: | 1744 else: |
1745 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): | 1745 if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): |
1746 remote_url = (cl.GetRemoteUrl() + '@' | 1746 remote_url = (cl.GetRemoteUrl() + '@' |
1747 + cl.GetUpstreamBranch().split('/')[-1]) | 1747 + cl.GetUpstreamBranch().split('/')[-1]) |
1748 if remote_url: | 1748 if remote_url: |
1749 upload_args.extend(['--base_url', remote_url]) | 1749 upload_args.extend(['--base_url', remote_url]) |
1750 remote, remote_branch = cl.GetRemoteBranch() | 1750 remote, remote_branch = cl.GetRemoteBranch() |
1751 if remote and remote_branch: | 1751 if remote and remote_branch: |
1752 # Create the true path to the remote branch. | 1752 if options.target_branch: |
agable
2015/01/07 21:45:09
And what if the user passes --target_branch=refs/h
Mike Wittman
2015/01/07 23:55:33
Good point. I've updated the branch recognition to
| |
1753 # Does the following translation: | 1753 if options.target_branch.startswith('branch-heads/'): |
1754 # * refs/remotes/origin/refs/diff/test -> refs/diff/test | 1754 remote_branch = 'refs/%s' % options.target_branch |
1755 # * refs/remotes/origin/master -> refs/heads/master | 1755 else: |
1756 # * refs/remotes/branch-heads/test -> refs/branch-heads/test | 1756 remote_branch = 'refs/heads/%s' % options.target_branch |
1757 if remote_branch.startswith('refs/remotes/%s/refs/' % remote): | 1757 else: |
1758 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, '') | 1758 # Create the true path to the remote branch. |
1759 elif remote_branch.startswith('refs/remotes/%s/' % remote): | 1759 # Does the following translation: |
1760 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, | 1760 # * refs/remotes/origin/refs/diff/test -> refs/diff/test |
1761 'refs/heads/') | 1761 # * refs/remotes/origin/master -> refs/heads/master |
1762 elif remote_branch.startswith('refs/remotes/branch-heads'): | 1762 # * refs/remotes/branch-heads/test -> refs/branch-heads/test |
1763 remote_branch = remote_branch.replace('refs/remotes/', 'refs/') | 1763 if remote_branch.startswith('refs/remotes/%s/refs/' % remote): |
1764 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, '') | |
1765 elif remote_branch.startswith('refs/remotes/%s/' % remote): | |
1766 remote_branch = remote_branch.replace('refs/remotes/%s/' % remote, | |
1767 'refs/heads/') | |
1768 elif remote_branch.startswith('refs/remotes/branch-heads'): | |
1769 remote_branch = remote_branch.replace('refs/remotes/', 'refs/') | |
1770 | |
1771 # Default to master for refs that are not branches. | |
1772 if not remote_branch.startswith('refs/branch-heads'): | |
1773 remote_branch = 'refs/heads/master' | |
1774 | |
1764 pending_prefix = settings.GetPendingRefPrefix() | 1775 pending_prefix = settings.GetPendingRefPrefix() |
1765 # If a pending prefix exists then replace refs/ with it. | 1776 # If a pending prefix exists then replace refs/ with it. |
1766 if pending_prefix: | 1777 if pending_prefix: |
1767 remote_branch = remote_branch.replace('refs/', pending_prefix) | 1778 remote_branch = remote_branch.replace('refs/', pending_prefix) |
1768 upload_args.extend(['--target_ref', remote_branch]) | 1779 upload_args.extend(['--target_ref', remote_branch]) |
1769 | 1780 |
1770 project = settings.GetProject() | 1781 project = settings.GetProject() |
1771 if project: | 1782 if project: |
1772 upload_args.extend(['--project', project]) | 1783 upload_args.extend(['--project', project]) |
1773 | 1784 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1835 '--emulate-svn-auto-props', | 1846 '--emulate-svn-auto-props', |
1836 action="store_true", | 1847 action="store_true", |
1837 dest="emulate_svn_auto_props", | 1848 dest="emulate_svn_auto_props", |
1838 help="Emulate Subversion's auto properties feature.") | 1849 help="Emulate Subversion's auto properties feature.") |
1839 parser.add_option('-c', '--use-commit-queue', action='store_true', | 1850 parser.add_option('-c', '--use-commit-queue', action='store_true', |
1840 help='tell the commit queue to commit this patchset') | 1851 help='tell the commit queue to commit this patchset') |
1841 parser.add_option('--private', action='store_true', | 1852 parser.add_option('--private', action='store_true', |
1842 help='set the review private (rietveld only)') | 1853 help='set the review private (rietveld only)') |
1843 parser.add_option('--target_branch', | 1854 parser.add_option('--target_branch', |
1844 '--target-branch', | 1855 '--target-branch', |
1845 help='When uploading to gerrit, remote branch to ' | 1856 help='Remote branch to use for CL. ' + |
agable
2015/01/07 21:45:09
As noted above, this text is not explicit enough t
Mike Wittman
2015/01/07 23:55:33
We should now handle all of these cases.
| |
1846 'use for CL. Default: master') | 1857 'Default: remote branch head, or master') |
1847 parser.add_option('--email', default=None, | 1858 parser.add_option('--email', default=None, |
1848 help='email address to use to connect to Rietveld') | 1859 help='email address to use to connect to Rietveld') |
1849 parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true', | 1860 parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true', |
1850 help='add a set of OWNERS to TBR') | 1861 help='add a set of OWNERS to TBR') |
1851 | 1862 |
1852 add_git_similarity(parser) | 1863 add_git_similarity(parser) |
1853 (options, args) = parser.parse_args(args) | 1864 (options, args) = parser.parse_args(args) |
1854 | 1865 |
1855 if options.target_branch and not settings.GetIsGerrit(): | |
1856 parser.error('Use --target_branch for non gerrit repository.') | |
1857 | |
1858 if is_dirty_git_tree('upload'): | 1866 if is_dirty_git_tree('upload'): |
1859 return 1 | 1867 return 1 |
1860 | 1868 |
1861 options.reviewers = cleanup_list(options.reviewers) | 1869 options.reviewers = cleanup_list(options.reviewers) |
1862 options.cc = cleanup_list(options.cc) | 1870 options.cc = cleanup_list(options.cc) |
1863 | 1871 |
1864 cl = Changelist() | 1872 cl = Changelist() |
1865 if args: | 1873 if args: |
1866 # TODO(ukai): is it ok for gerrit case? | 1874 # TODO(ukai): is it ok for gerrit case? |
1867 base_branch = args[0] | 1875 base_branch = args[0] |
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2938 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2946 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
2939 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2947 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
2940 | 2948 |
2941 | 2949 |
2942 if __name__ == '__main__': | 2950 if __name__ == '__main__': |
2943 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2951 # These affect sys.stdout so do it outside of main() to simplify mocks in |
2944 # unit testing. | 2952 # unit testing. |
2945 fix_encoding.fix_encoding() | 2953 fix_encoding.fix_encoding() |
2946 colorama.init() | 2954 colorama.init() |
2947 sys.exit(main(sys.argv[1:])) | 2955 sys.exit(main(sys.argv[1:])) |
OLD | NEW |