在PHP中git post-receive hook [英] git post-receive hook in php

查看:85
本文介绍了在PHP中git post-receive hook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在post-receive hook上执行一个php hook,将git repo中的文件复制到同一台服务器上的web文件夹中,并且只有在被忽略其他分支的主分支上进行推送时才能运行。下面是我到目前为止。

I want to be able to execute a php hook on post-receive hook, to copy files from the git repo to web folder on the same server and only run if it was pushed was made on a master branch ignoring other branches. Below is what I've got so far.

!/usr/bin/php
<?php

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

?>

基本上,我不确定如何使用php访问git参数。

Basically, im not sure how to access git arguments using php.

推荐答案

不要忘记post-receive hook doesn不接受参数 :它读取stdin上的数据。

Don't forget a post-receive hook doesn't take arguments: it reads data on stdin.


运行post-receive脚本收件包已接受包并且存储库已更新后。它以参数形式通过stdin传递:

The "post-receive" script is run after receive-pack has accepted a pack and the repository has been updated. It is passed arguments in through stdin in the form:



<oldrev> <newrev> <refname>

所以你需要读取提取分支(该示例位于bash中,但您可以修改它)

So you will need to read said arguments to extract the branch (the example is in bash but you can adapt it)

这篇关于在PHP中git post-receive hook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆