[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """Wrapper for trychange.py for git checkout.""" |
| 6 | |
| 7 | import logging |
| 8 | import sys |
| 9 | |
| 10 | import breakpad # pylint: disable=W0611 |
| 11 | |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 12 | from scm import GIT |
[email protected] | 0112bfb | 2011-09-08 20:54:04 | [diff] [blame] | 13 | import subprocess2 |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 14 | import third_party.upload |
| 15 | import trychange |
[email protected] | 1516995 | 2011-09-27 14:30:53 | [diff] [blame] | 16 | import git_cl |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 17 | |
| 18 | |
| 19 | def GetRietveldIssueNumber(): |
| 20 | try: |
| 21 | return GIT.Capture( |
[email protected] | 80a9ef1 | 2011-12-13 20:44:10 | [diff] [blame] | 22 | ['config', 'branch.%s.rietveldissue' % GIT.GetBranch('.')], |
| 23 | '.').strip() |
[email protected] | 0112bfb | 2011-09-08 20:54:04 | [diff] [blame] | 24 | except subprocess2.CalledProcessError: |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 25 | return None |
| 26 | |
| 27 | |
| 28 | def GetRietveldPatchsetNumber(): |
| 29 | try: |
| 30 | return GIT.Capture( |
[email protected] | 80a9ef1 | 2011-12-13 20:44:10 | [diff] [blame] | 31 | ['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch('.')], |
| 32 | '.').strip() |
[email protected] | 0112bfb | 2011-09-08 20:54:04 | [diff] [blame] | 33 | except subprocess2.CalledProcessError: |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 34 | return None |
| 35 | |
| 36 | |
| 37 | def GetRietveldServerUrl(): |
| 38 | try: |
[email protected] | 80a9ef1 | 2011-12-13 20:44:10 | [diff] [blame] | 39 | return GIT.Capture(['config', 'rietveld.server'], '.').strip() |
[email protected] | 0112bfb | 2011-09-08 20:54:04 | [diff] [blame] | 40 | except subprocess2.CalledProcessError: |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 41 | return None |
| 42 | |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | args = sys.argv[1:] |
| 46 | patchset = GetRietveldPatchsetNumber() |
| 47 | if patchset: |
| 48 | args.extend([ |
| 49 | '--issue', GetRietveldIssueNumber(), |
| 50 | '--patchset', patchset, |
| 51 | ]) |
| 52 | else: |
| 53 | rietveld_url = GetRietveldServerUrl() |
| 54 | if rietveld_url: |
| 55 | args.extend(['--rietveld_url', GetRietveldServerUrl()]) |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 56 | try: |
[email protected] | 1516995 | 2011-09-27 14:30:53 | [diff] [blame] | 57 | cl = git_cl.Changelist() |
| 58 | change = cl.GetChange(cl.GetUpstreamBranch(), None) |
[email protected] | 51f44f4 | 2011-10-08 02:20:44 | [diff] [blame] | 59 | # Hack around a limitation in logging. |
| 60 | logging.getLogger().handlers = [] |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 61 | sys.exit(trychange.TryChange( |
[email protected] | 2896eda | 2011-10-05 05:38:37 | [diff] [blame] | 62 | args, change, swallow_exception=False, |
[email protected] | 79d9848 | 2011-06-14 18:44:31 | [diff] [blame] | 63 | prog='git try', |
[email protected] | bbb4665 | 2011-06-14 18:30:26 | [diff] [blame] | 64 | extra_epilog='\n' |
| 65 | 'git try will diff against your tracked branch and will ' |
| 66 | 'detect your rietveld\n' |
| 67 | 'code review if you are using git-cl\n')) |
| 68 | except third_party.upload.ClientLoginError, e: |
| 69 | print('Got an exception while trying to log in to Rietveld.') |
| 70 | print(str(e)) |