问题
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