代码中有TODO时如何禁用git push? [英] How to disable git push when there are TODOs in code?
问题描述
我们团队中存在一个问题,我们决定检查是否有方法或git命令拒绝代码中存在TODO的git push。
任何想法?
在此先感谢。
不可能在github中使用预接收钩子,所以我们使用pre - 在客户端提交钩子:
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
用于`git diff-index -p -M - 名称状态HEAD - | cut -c3-`;如果[grep'TODO'$ FILE]
然后
echo $ FILE'包含TODO'
出口1
fi
完成$ b,则执行
$ b exit
我们在我们的控制版本系统下创建了一个符号链接, .git / hooks
感谢您的帮助:)
编辑:因为if语句中的grep行为,我们需要编辑我们的脚本:
#!/ bin / sh
在`git diff --name-only --cached`; do
grep'TODO'$ FILE 2>& 1> / dev / null
if [$? -eq 0];那么
echo $ FILE'包含TODO'
出口1
fi
完成
出口
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.
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
这篇关于代码中有TODO时如何禁用git push?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!