【发布时间】:2018-03-07 09:30:27
【问题描述】:
大师
我刚刚发现通过 HTTP 执行 git-push 时无法运行 git 挂钩(接收前、接收后),但是通过 SSH 执行 git-push 时可以调用这些挂钩。
是这样吗?
那么,当我们使用 HTTP 作为访问协议时,如何使 git/hooks/pre-receive 工作?
/// -------------------------------------------- -------------------------------------------------- --
/// @服务器
/// 这是接收后的钩子代码
hello.git $ cat hooks/post-receive
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
#git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
/// -------------------------------------------- -------------------------------------------------- --
/// @客户
/// 这里 git/hooks/post-receive 工作,而 git push 通过 SSH。
$ git push
user01@hostxxx.net's password:
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 390 bytes | 390.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote: Master ref received. Deploying master branch to production...
To hostxxx.net:/var/www/html/repo/hello.git
a308dbc..82184b8 master -> master
【问题讨论】:
-
你使用什么服务器来推送 HTTP?
-
我们为我们的业务设置了一台位于互联网的服务器,由于代理服务器的安全限制,我们不得不使用 HTTP/HTTPS 协议而不是 SSH。所以可以给我任何建议吗?
-
是的,但是服务器到底是什么?简单的HTTP服务器肯定不会运行服务器端的hook,需要配置git-http-backend。
-
提前致谢。我可以尽快检查并回复您。