代码中有TODO时如何禁用git push? [英] How to disable git push when there are TODOs in code?

查看:290
本文介绍了代码中有TODO时如何禁用git push?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们团队中存在一个问题,我们决定检查是否有方法或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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆