我想在每次git推送之前运行一个单元测试,如果测试失败,取消推送,但我甚至找不到预推钩子,只有预提交和预重基地。
发布于 2010-11-16 16:48:47
我宁愿在预提交钩子中运行测试。因为在提交时已经记录了更改。推送和拉取仅交换关于已记录的更改的信息。如果测试失败,那么您的存储库中就已经有了一个“损坏的”版本。不管你是不是在推它。
发布于 2013-02-03 13:17:13
Git在1.8.2
版本中获得了pre-push
钩子。
示例pre-push
脚本:https://github.com/git/git/blob/87c86dd14abe8db7d00b0df5661ef8cf147a72a3/templates/hooks--pre-push.sample
1.8.2发布说明谈论新的预推钩子:https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.txt
发布于 2014-01-29 14:57:24
Git在1.8.2版本中获得了预推钩子。
预推钩子和预提交钩子都是我需要的。除了保护分支之外,它们还可以提供与预提交挂钩相结合的额外安全性。
以及如何使用的示例(从this nice entry获取、采用和增强)
登录流浪者,运行测试,然后推送的简单示例
#!/bin/bash
# Run the following command in the root of your project to install this pre-push hook:
# cp git-hooks/pre-push .git/hooks/pre-push; chmod 700 .git/hooks/pre-push
CMD="ssh vagrant@192.168.33.10 -i ~/.vagrant.d/insecure_private_key 'cd /vagrant/tests; /vagrant/vendor/bin/phpunit'"
protected_branch='master'
# Check if we actually have commits to push
commits=`git log @{u}..`
if [ -z "$commits" ]; then
exit 0
fi
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [[ $current_branch = $protected_branch ]]; then
eval $CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed $CMD"
exit 1
fi
fi
exit 0
正如您所看到的,该示例使用了一个受保护的分支,即pre-push钩子的主题。
https://stackoverflow.com/questions/4196148
复制相似问题