3

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.

madphp
  • 1,716
  • 5
  • 31
  • 72

1 Answers1

0

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)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • On reading from stdin from a php script: http://stackoverflow.com/questions/554760/php-standard-input, or http://stackoverflow.com/questions/2390604/how-to-pass-variables-as-stdin-into-command-line-from-php if `php://stdin` isn't the right stream to read from. – VonC Jan 24 '12 at 07:35