中午花了20分钟修复了gitlint无法在windows使用的问题。python不太熟悉,不确定是否有更好的方法。
def build_git_context(lint_config, msg_filename, commit_hash, refspec):
""" Builds a git context based on passed parameters and order of precedence """
# Determine which GitContext method to use if a custom message is passed
from_commit_msg = GitContext.from_commit_msg
if lint_config.staged:
LOG.debug("Fetching additional meta-data from staged commit")
from_commit_msg = lambda message: GitContext.from_staged_commit(message, lint_config.target) # noqa
# Order of precedence:
# 1. Any data specified via --msg-filename
if msg_filename:
LOG.debug("Using --msg-filename.")
print(msg_filename)
#UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position
#缺省是gbk编码,无法提交中文,需要修改为utf-8就可以了。
msg_filename = open(msg_filename.name,'r',encoding='UTF-8')
return from_commit_msg(str(msg_filename.read()))
.gitlint文件放到repo下面。