git post-receive hook in php

痞子三分冷 提交于 2020-01-04 05:20:26

问题


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);

?>

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


回答1:


Don't forget a post-receive hook doesn't take arguments: it reads data on 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>

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



来源:https://stackoverflow.com/questions/8981152/git-post-receive-hook-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!