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存储库中是否已经存在传入提交消息的提交的主要内容,如果未能解决你的问题,请参考以下文章

git hook之commit-msg用于检测提交时间是否正确

Python 中的 Git Commit-Msg。收到 EOF 错误

解决fatal: cannot run .git/hooks/commit-msg: No such file or directory的问题

git学习--commit-msg缺失导致的missing Change-Id问题分析

手写 git hooks 脚本(pre-commitcommit-msg)

[原创]升级Gerrit的commit-msg,检查git commit时必须填写开发任务编号TaskID