Git pre-push 挂钩似乎无法与 git push 一起使用
Git pre-push hook doesn't seem to be working with git push
我在我的测试分支上:
$git branch
master
* testbranch
这是我在 .git/hooks/pre-push
文件中的代码:
#!/bin/bash
protected_branch='testbranch'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),,')
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
调用,我是不是漏掉了什么?
从您的描述看来,您正在尝试将 pre-receive
挂钩放入您的本地存储库。这不是它的工作原理 - pre-receive
挂钩应该在你的遥控器上。如果你想在推送之前在本地 运行 一些东西,使用 pre-push
挂钩。
the documentation 中列出了其他几个您可能也会觉得有用的挂钩。
我在我的测试分支上:
$git branch
master
* testbranch
这是我在 .git/hooks/pre-push
文件中的代码:
#!/bin/bash
protected_branch='testbranch'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),,')
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
调用,我是不是漏掉了什么?
从您的描述看来,您正在尝试将 pre-receive
挂钩放入您的本地存储库。这不是它的工作原理 - pre-receive
挂钩应该在你的遥控器上。如果你想在推送之前在本地 运行 一些东西,使用 pre-push
挂钩。
the documentation 中列出了其他几个您可能也会觉得有用的挂钩。