2012-01-24 76 views
3

我希望能够执行一个PHP挂钩后接收挂钩,将文件从git repo复制到同一服务器上的web文件夹,并且只有在被推入时才运行一个主分支忽略其他分支。以下是我到目前为止所做的。git后接收挂钩在php

!/usr/bin/php 
<?php 

exec("git archive master | tar -x -C /var/www/", $output); 

?> 

基本上,即时通讯不知道如何访问使用php的git参数。

+0

1,因为Git是:它通过标准输入的形式传递的参数中真棒,我不想研究细节。希望别人会照顾这个很快,我们都可以变得更聪明:) – rdlowrey

+0

a)抓住你选择的git库b)学习一些bash – Reactormonk

+0

好的。编号喜欢使用PHP,如果它对你完全一样。 – madphp

回答

0

不要忘记post-receive钩子doesn't take arguments:它读取stdin上的数据。

“接收后”脚本在接收包已接受包并且存储库已更新后运行。

<oldrev> <newrev> <refname> 

所以,你需要阅读该参数extract the branch(例子是在bash,但你能适应它)

+0

从一个PHP脚本从标准输入读取:http://stackoverflow.com/questions/554760/php-standard-input,或http://stackoverflow.com/questions/2390604/how-to-pass-variables-as -stdin-into-command-line-from-php if'php:// stdin' is not the right stream to read from。 – VonC