blob: f8f6d306a86c921032090ca45dbdc37780bd2dd9 [file] [log] [blame]
[email protected]bbb46652011-06-14 18:30:261#!/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
7import logging
8import sys
9
10import breakpad # pylint: disable=W0611
11
[email protected]bbb46652011-06-14 18:30:2612from scm import GIT
[email protected]0112bfb2011-09-08 20:54:0413import subprocess2
[email protected]bbb46652011-06-14 18:30:2614import third_party.upload
15import trychange
[email protected]15169952011-09-27 14:30:5316import git_cl
[email protected]bbb46652011-06-14 18:30:2617
18
19def GetRietveldIssueNumber():
20 try:
21 return GIT.Capture(
[email protected]80a9ef12011-12-13 20:44:1022 ['config', 'branch.%s.rietveldissue' % GIT.GetBranch('.')],
23 '.').strip()
[email protected]0112bfb2011-09-08 20:54:0424 except subprocess2.CalledProcessError:
[email protected]bbb46652011-06-14 18:30:2625 return None
26
27
28def GetRietveldPatchsetNumber():
29 try:
30 return GIT.Capture(
[email protected]80a9ef12011-12-13 20:44:1031 ['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch('.')],
32 '.').strip()
[email protected]0112bfb2011-09-08 20:54:0433 except subprocess2.CalledProcessError:
[email protected]bbb46652011-06-14 18:30:2634 return None
35
36
37def GetRietveldServerUrl():
38 try:
[email protected]80a9ef12011-12-13 20:44:1039 return GIT.Capture(['config', 'rietveld.server'], '.').strip()
[email protected]0112bfb2011-09-08 20:54:0440 except subprocess2.CalledProcessError:
[email protected]bbb46652011-06-14 18:30:2641 return None
42
43
[email protected]013731e2015-02-26 18:28:4344def main(args):
[email protected]bbb46652011-06-14 18:30:2645 patchset = GetRietveldPatchsetNumber()
46 if patchset:
47 args.extend([
48 '--issue', GetRietveldIssueNumber(),
49 '--patchset', patchset,
50 ])
51 else:
52 rietveld_url = GetRietveldServerUrl()
53 if rietveld_url:
54 args.extend(['--rietveld_url', GetRietveldServerUrl()])
[email protected]bbb46652011-06-14 18:30:2655 try:
[email protected]15169952011-09-27 14:30:5356 cl = git_cl.Changelist()
57 change = cl.GetChange(cl.GetUpstreamBranch(), None)
[email protected]51f44f42011-10-08 02:20:4458 # Hack around a limitation in logging.
59 logging.getLogger().handlers = []
[email protected]bbb46652011-06-14 18:30:2660 sys.exit(trychange.TryChange(
[email protected]2896eda2011-10-05 05:38:3761 args, change, swallow_exception=False,
[email protected]79d98482011-06-14 18:44:3162 prog='git try',
[email protected]bbb46652011-06-14 18:30:2663 extra_epilog='\n'
64 'git try will diff against your tracked branch and will '
65 'detect your rietveld\n'
66 'code review if you are using git-cl\n'))
67 except third_party.upload.ClientLoginError, e:
68 print('Got an exception while trying to log in to Rietveld.')
69 print(str(e))
[email protected]013731e2015-02-26 18:28:4370 return 0
71
72
73if __name__ == '__main__':
74 try:
75 sys.exit(main(sys.argv[1:]))
76 except KeyboardInterrupt:
77 sys.stderr.write('interrupted\n')
78 sys.exit(1)