每次有人提交.doc文件时,Git挂钩都会显示一条消息

时间:2016-03-10 13:35:45

标签: git hook githooks git-commit pre-commit-hook

我想知道每次提交Word文档(.doc / .docx)文件时如何使用Git钩子显示消息,让人们知道他们应该提交.xml文件。

1 个答案:

答案 0 :(得分:0)

这样的事可能有用:

#!/bin/sh

TMP="$PWD/.tmp"
git status --porcelain | grep '.doc' > "$TMP"

while read -r commitLine; do
    added=$(printf '%s\n' "$commitLine" | cut -c1)
    test "$added" = "A" && {
        commitLine=$(printf '%s\n' "$commitLine" | cut -d\  -f 3-)
        list=$(printf "${list}${commitLine}\n")
    }
done < "$TMP"
rm "$TMP"

test ! -z "$list" && {
    cat << EOF
Doc and Docx files currently staged:

${list}

Please remove them before commit.
EOF
    exit 1
}

将其写入.git / hooks / pre-commit

中的可执行文件