Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kujiy/7cd18c2b5e15020d58a7f3f185165c68 to your computer and use it in GitHub Desktop.
Save kujiy/7cd18c2b5e15020d58a7f3f185165c68 to your computer and use it in GitHub Desktop.
<?php
// Use in the "Post-Receive URLs" section of your Bitbucket repo.
if ( $_POST['payload'] ) {
$data = json_decode($_POST['payload']);
$commits = $data->{"commits"};
// This code checks to see if commits were made to a specific branch, and if so, performs a git reset/pull
foreach ($commits as $commit_obj) {
$branch = $commit_obj->{"branch"};
if ($branch == 'my-branch') {
$output = shell_exec('cd /path/to/my/httpdocs && git reset --hard HEAD && git pull');
echo "Output: <pre>$output</pre>";
// TODO: Check for error statuses, respond appropriately
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment