-
-
Save MikeTodd/5862043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
This script will check for updates to a given branch, and if so, perform a Git reset and pull. This is good for use if, for example, you are working on a development branch for a website and need your dev server to automatically pull every time a commit is made.