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