How to disable git push when there are TODOs in code?

我与影子孤独终老i 提交于 2019-11-27 05:56:53

问题


We are having an issue in our team and we have decided to check if there is a way or git command to reject git push where there are TODOs in the code. Any ideas? Thanks in advance.


回答1:


Is not possible use pre-receive hooks in github, so we are using instead pre-commit hook in client side: http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Client-Side-Hooks

Our pre-commit script (based on http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes) looks like:

#!/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

We have this script under our control version system, and create a symbolic link to it in .git/hooks

Thanks for the help :)

EDIT: because of grep behaviour in if statement we needed to edit our script:

#!/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



回答2:


Pre-receive hook on the server, grep the files and abort the push :)

More info on the pre-receive hook can be found here: http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Server-Side-Hooks



来源:https://stackoverflow.com/questions/13877469/how-to-disable-git-push-when-there-are-todos-in-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!