当前位置: 首页>>代码示例>>Python>>正文


Python Git.rev_parse方法代码示例

本文整理汇总了Python中git.cmd.Git.rev_parse方法的典型用法代码示例。如果您正苦于以下问题:Python Git.rev_parse方法的具体用法?Python Git.rev_parse怎么用?Python Git.rev_parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.cmd.Git的用法示例。


在下文中一共展示了Git.rev_parse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import rev_parse [as 别名]
def main():
    global TAB_WIDTH

    git_exec = Git()
    output = git_exec.rev_parse('--show-toplevel', with_extended_output=True,
                                with_exceptions=False)
    err_no, git_root, err_msg = output
    if err_no:
        print >> sys.stderr, err_msg
        sys.exit(1)

    git_repo = Repo(git_root)
    git_config = git_repo.config_reader()

    ws_config = {
        'blank-at-eol': True,
        'space-before-tab': True,
        'indent-with-non-tab': False,
        'tab-in-indent': False,
        'blank-at-eof': False,
        'trailing-space': False,
        'cr-at-eol': False,
    }
    try:
        _config_whitespace = git_config.get('core', 'whitespace')
        for c in _config_whitespace.split(','):
            c = c.strip()

            if 'tabwidth' in c:
                ws_config['tabwidth'] = int(c.split('=').pop())
            else:
                if c[0] == '-':  # e.g. -tab-in-indent
                    ws_config[c[1:]] = False
                else:
                    ws_config[c] = True
    except:
        pass

    if ws_config.get('tab-in-indent', False) and \
       ws_config.get('indent-with-non-tab', False):
        print >> sys.stderr, \
                 'Cannot enforce both tab-in-indent and indent-with-non-tab.'
        sys.exit(1)

    TAB_WIDTH = ws_config.get('tabwidth')
    sanitizers = []

    if ws_config.get('trailing-space', False):
        ws_config['blank-at-eol'] = True
        ws_config['blank-at-eof'] = True

    # Allow overrides gitconfig by cli argument
    arg_parser = argparse.ArgumentParser()
    arg_parser.set_defaults(**ws_config)

    arg_parser.add_argument('--trailing-space', dest='trailing-space',
                            type=ast.literal_eval, metavar='True|False',
                            help='trailing-space is a short-hand to cover '
                                 'both blank-at-eol and blank-at-eof')
    arg_parser.add_argument('--blank-at-eol', dest='blank-at-eol',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats trailing whitespaces at the end of '
                                 'the line as an error')
    arg_parser.add_argument('--space-before-tab', dest='space-before-tab',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a space character that appears '
                                 'immediately before a tab character in the '
                                 'initial indent part of the line as an error')
    arg_parser.add_argument('--indent-with-non-tab',
                            dest='indent-with-non-tab',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a line that is indented with 8 or '
                                 'more space characters as an error')
    arg_parser.add_argument('--tab-in-indent', dest='tab-in-indent',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a tab character in the initial '
                                 'indent part of the line as an error')
#    arg_parser.add_argument('--blank-at-eof', dest='blank-at-eof',
#                            type=ast.literal_eval, metavar='True|False',
#                            help='treats blank lines added at the end of '
#                                 'file as an error')
    arg_parser.add_argument('--cr-at-eol', dest='cr-at-eol',
                            type=ast.literal_eval, metavar='True|False',
                            help='treats a carriage-return at the end of '
                                 'line as part of the line terminator, i.e. '
                                 'with it, trailing-space does not trigger '
                                 'if the character before such a '
                                 'carriage-return is not a whitespace')
    arg_parser.add_argument('--tabwidth', type=int, metavar='',
                            help='tells how many character positions a tab '
                                 'occupies; this is relevant for '
                                 'indent-with-non-tab and when git fixes '
                                 'tab-in-indent errors. The default tab '
                                 'width is 8.')

    arg_parser.add_argument('-d', '--debug', action='store_true',
                            help='Print the whitespace config')

    args = arg_parser.parse_args()
    ws_config = vars(args)
#.........这里部分代码省略.........
开发者ID:mrkschan,项目名称:git-fix-whitespace,代码行数:103,代码来源:git_fix_whitespace.py


注:本文中的git.cmd.Git.rev_parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。