blob: 45a5217e6f2a5fdd665af049c7f57b867ca98228 [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
44if __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]bbb46652011-06-14 18:30:2656 try:
[email protected]15169952011-09-27 14:30:5357 cl = git_cl.Changelist()
58 change = cl.GetChange(cl.GetUpstreamBranch(), None)
[email protected]51f44f42011-10-08 02:20:4459 # Hack around a limitation in logging.
60 logging.getLogger().handlers = []
[email protected]bbb46652011-06-14 18:30:2661 sys.exit(trychange.TryChange(
[email protected]2896eda2011-10-05 05:38:3762 args, change, swallow_exception=False,
[email protected]79d98482011-06-14 18:44:3163 prog='git try',
[email protected]bbb46652011-06-14 18:30:2664 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))