我正在考场上
$git branch
master
* testbranch
这是我在.git/hooks/pre-push
文件中的代码:
#!/bin/bash
protected_branch='testbranch'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "Test"
pwdlsfail
rc=$?
if [[ $rc != 0 ]] ; then
echo "test failed - push denied. Run tests locally and confirm they pass before pushing"
exit $rc
fi
else
# Everything went OK so we can exit with a zero
exit 0
fi
尝试将以上代码作为shell脚本运行,并且运行良好:
$./1.sh
Test
./1.sh: line 8: pwdlsfail: command not found
test failed on rev - push denied. Run tests locally and confirm they pass before pushing
但是pre-push
钩子仍然没有被git push origin testbranch
调用,我丢失了什么吗?
答案 0 :(得分:1)
从您的描述中可以看出,您正在尝试将pre-receive
钩子放入本地存储库。那不是它的工作原理-pre-receive
钩子应该在您的遥控器上。如果要在推送之前在本地运行某些内容,请使用pre-push
挂钩。
the documentation中还列出了其他一些有用的钩子。