python commit-msg hook检查git存储库中是否已经存在传入提交消息的提交

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python commit-msg hook检查git存储库中是否已经存在传入提交消息的提交相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python

from subprocess import check_output
import sys

class Colors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

COMMIT_MSG = ""
for s in [(s) for s in sys.argv if s == ".git/COMMIT_EDITMSG"]:
    with open(s, 'r') as f:
        COMMIT_MSG = f.read().rstrip()

for line in check_output(["git", "log", "--pretty=format:%s"]).splitlines():
    if line.rstrip() == COMMIT_MSG:
        print Colors.FAIL, "[DUPLICATE]",
        print "There has already been a commit in this repository with '", line.rstrip(),
        print "' commit message!"
        exit(1)

以上是关于python commit-msg hook检查git存储库中是否已经存在传入提交消息的提交的主要内容,如果未能解决你的问题,请参考以下文章