Skip to content

Instantly share code, notes, and snippets.

@ibejohn818
Created July 19, 2016 03:40
Show Gist options
  • Save ibejohn818/5b393602f39576711093dcc610457992 to your computer and use it in GitHub Desktop.
Save ibejohn818/5b393602f39576711093dcc610457992 to your computer and use it in GitHub Desktop.
Git Deploy Use-case
#!/usr/bin/env php
<?php
$in = fopen("php://stdin","r");
$line = fgets($in);
preg_match_all('/(.*)( )(.*)( )(.*)/',$line,$matches);
if(!isset($matches[5][0])) {
exit;
}
$ref = $matches[5][0];
$repo = preg_match_all('/^refs\/heads\/(.*)/',$ref,$matches);
//THE REPO NAME
$repo = $matches[1][0];
$cwd = str_replace("/.git","",getcwd());
file_put_contents("/tmp/ugh",$cwd);
//set the GIT_DIR env var to our working tree
passthru("export GIT_WORK_TREE='{$cwd}' && git checkout -f {$ref}");
chdir($cwd);
passthru("composer install --no-dev");
passthru("composer dumpautoload -o");
passthru("bower install");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment