当代码中有TODO时如何禁用git push?

时间:2012-12-14 11:08:34

标签: git push todo

我们的团队遇到了问题,我们决定检查是否有方法或git命令拒绝git push代码中有TODO的地方。 有任何想法吗? 提前谢谢。

2 个答案:

答案 0 :(得分:13)

不可能在github中使用pre-receive钩子,所以我们在客户端使用pre-commit hook: http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Client-Side-Hooks

我们的预提交脚本(基于http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes)如下所示:

#!/bin/sh

for FILE in `git diff-index -p -M --name-status HEAD -- | cut -c3-` ; do
    if [ "grep 'TODO' $FILE" ]
    then
        echo $FILE ' contains TODO'
        exit 1
    fi
done
exit

我们在我们的控制版本系统下有这个脚本,并在.git / hooks中创建一个符号链接

感谢您的帮助:)

编辑:因为if语句中的grep行为我们需要编辑脚本:

#!/bin/sh

for FILE in `git diff --name-only --cached`; do
    grep 'TODO' $FILE 2>&1 >/dev/null
    if [ $? -eq 0 ]; then
        echo $FILE ' contains TODO'
        exit 1
    fi
done
exit

答案 1 :(得分:4)

在服务器上预先接收挂钩,grep文件并中止推送:)

有关预接收挂钩的更多信息,请访问:http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Server-Side-Hooks