Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created November 16, 2010 06:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjangda/701537 to your computer and use it in GitHub Desktop.
Save mjangda/701537 to your computer and use it in GitHub Desktop.
Quick and dirty script that can auto-pull to keep your repo up-to-date any time something is pushed to the remote repo
<?php
// Edit these to match your environment settings
define( 'BASE_PATH', '/home/username/webapps' );
// This is the path to the git executable
define( 'GIT_PATH', get_full_path( '/git/bin/git' ) );
// Edit this array so the key matches the github repo name and the value is path of the repo relative to the BASE_PATH
$repository_paths = array(
'test' => '/git-test'
);
if( isset( $_POST['payload'] ) ) {
$payload = json_decode( stripslashes( $_POST['payload'] ) );
if( isset( $repository_paths[ $payload->repository->name ] ) ) {
$path = get_full_path( $repository_paths[ $payload->repository->name ] );
$cmd = sprintf( 'cd %s; ', $path );
$cmd .= sprintf( '%s pull', GIT_PATH );
shell_exec( $cmd );
die( "Executed: $cmd!" );
}
}
die( 'Dont\'t think you\'re sposed to be here...' );
function get_full_path( $path ) {
return BASE_PATH . $path;
}
@mjangda
Copy link
Author

mjangda commented Nov 16, 2010

Written for my setup on Webfaction so it's unlikely to work as-is for others. You likely have to tweak the base and git paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment