Skip to content

Instantly share code, notes, and snippets.

@timdream
Last active October 2, 2015 21:38
Show Gist options
  • Save timdream/2326349 to your computer and use it in GitHub Desktop.
Save timdream/2326349 to your computer and use it in GitHub Desktop.
Minimuist pull me script that work with Github hook
<?php
/* host machine settings */
$GIT_BIN = '/usr/local/bin/git';
$LOCAL_USER = 'www';
/* remote repo settings */
$REMOTE = 'origin';
$BRANCH = 'production';
header('Content-Type: text/plain; charset=UTF-8');
if (!isset($argv) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
print <<<EOL
Error: Use POST request to update.
For testing, use 'curl -d dummy=data'.
EOL;
exit;
}
if ( trim(exec('whoami')) !== $LOCAL_USER) {
print 'Error: Must run as the specified user.';
exit;
}
system(
"$GIT_BIN fetch $REMOTE 2>&1 && " .
"$GIT_BIN checkout -q $REMOTE/$BRANCH 2>&1 && " .
"$GIT_BIN submodule -q update --init 2>&1; " .
"$GIT_BIN log -1 2>&1"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment