Skip to content

Instantly share code, notes, and snippets.

@atmoz
Created June 20, 2012 22:16
Show Gist options
  • Save atmoz/2962556 to your computer and use it in GitHub Desktop.
Save atmoz/2962556 to your computer and use it in GitHub Desktop.
Git hook script in PHP for deploying code with push
#!/usr/bin/php
<?php
function deploy($branch) {
$branchPaths = array(
'master' => '/home/web/example.com',
'develop' => '/home/web/test.example.com'
);
if (array_key_exists($branch, $branchPaths)) {
$path = $branchPaths[$branch];
// Need some more testing here ...
exec("git archive $branch | tar -xC $path");
echo "NOTICE: $branch branch is deployed to $path!";
}
}
function branchFromRefname($refname) {
$parts = explode('/', trim($refname));
return $parts[2];
}
// Receive arguments from stdin
$in = fopen('php://stdin', 'r');
while ($line = fgets($in)) {
$args = explode(' ', $line);
deploy(branchFromRefname($args[2]));
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment