OLD | NEW |
| (Empty) |
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 from scm import GIT | |
11 import subprocess2 | |
12 import third_party.upload | |
13 import trychange | |
14 import git_cl | |
15 | |
16 | |
17 def GetRietveldIssueNumber(): | |
18 try: | |
19 return GIT.Capture( | |
20 ['config', 'branch.%s.rietveldissue' % GIT.GetBranch('.')], | |
21 '.').strip() | |
22 except subprocess2.CalledProcessError: | |
23 return None | |
24 | |
25 | |
26 def GetRietveldPatchsetNumber(): | |
27 try: | |
28 return GIT.Capture( | |
29 ['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch('.')], | |
30 '.').strip() | |
31 except subprocess2.CalledProcessError: | |
32 return None | |
33 | |
34 | |
35 def GetRietveldServerUrl(): | |
36 try: | |
37 return GIT.Capture(['config', 'rietveld.server'], '.').strip() | |
38 except subprocess2.CalledProcessError: | |
39 return None | |
40 | |
41 | |
42 def main(args): | |
43 patchset = GetRietveldPatchsetNumber() | |
44 if patchset: | |
45 args.extend([ | |
46 '--issue', GetRietveldIssueNumber(), | |
47 '--patchset', patchset, | |
48 ]) | |
49 else: | |
50 rietveld_url = GetRietveldServerUrl() | |
51 if rietveld_url: | |
52 args.extend(['--rietveld_url', GetRietveldServerUrl()]) | |
53 try: | |
54 cl = git_cl.Changelist() | |
55 change = cl.GetChange(cl.GetUpstreamBranch(), None) | |
56 # Hack around a limitation in logging. | |
57 logging.getLogger().handlers = [] | |
58 sys.exit(trychange.TryChange( | |
59 args, change, swallow_exception=False, | |
60 prog='git try', | |
61 extra_epilog='\n' | |
62 'git try will diff against your tracked branch and will ' | |
63 'detect your rietveld\n' | |
64 'code review if you are using git-cl\n')) | |
65 except third_party.upload.ClientLoginError, e: | |
66 print('Got an exception while trying to log in to Rietveld.') | |
67 print(str(e)) | |
68 return 0 | |
69 | |
70 | |
71 if __name__ == '__main__': | |
72 try: | |
73 sys.exit(main(sys.argv[1:])) | |
74 except KeyboardInterrupt: | |
75 sys.stderr.write('interrupted\n') | |
76 sys.exit(1) | |
OLD | NEW |