git-try 1.74 KB
Newer Older
1
#!/usr/bin/python
2
# Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 4
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
5
"""Wrapper for trychange.py for git checkout."""
6

7
import logging
8 9
import sys

10
import breakpad  # pylint: disable=W0611
11

12
import gclient_utils
13
from scm import GIT
14
import third_party.upload
15
import trychange
16

17 18

def GetRietveldIssueNumber():
19 20 21 22 23
  try:
    return GIT.Capture(
        ['config', 'branch.%s.rietveldissue' % GIT.GetBranch(None)])
  except gclient_utils.Error:
    return None
24 25 26


def GetRietveldPatchsetNumber():
27 28 29 30 31
  try:
    return GIT.Capture(
        ['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch(None)])
  except gclient_utils.Error:
    return None
32 33


34
def GetRietveldServerUrl():
35 36 37 38
  try:
    return GIT.Capture(['config', 'rietveld.server']).strip()
  except gclient_utils.Error:
    return None
39 40


41
if __name__ == '__main__':
42
  args = sys.argv[1:]
43 44
  patchset = GetRietveldPatchsetNumber()
  if patchset:
45 46
    args.extend([
        '--issue', GetRietveldIssueNumber(),
47
        '--patchset', patchset,
48
    ])
49 50 51 52
  else:
    rietveld_url = GetRietveldServerUrl()
    if rietveld_url:
      args.extend(['--rietveld_url', GetRietveldServerUrl()])
53 54
  # Hack around a limitation in logging.
  logging.getLogger().handlers = []
55 56 57 58 59 60 61 62 63 64 65
  try:
    sys.exit(trychange.TryChange(
        args, file_list=[], swallow_exception=False,
        prog='git-try',
        extra_epilog='\n'
                     'git-try will diff against your tracked branch and will '
                     'detect your rietveld\n'
                     'code review if you are using git-cl\n'))
  except third_party.upload.ClientLoginError, e:
    print('Got an exception while trying to log in to Rietveld.')
    print(str(e))