Created
August 28, 2013 23:06
-
-
Save cfg/6372509 to your computer and use it in GitHub Desktop.
Dirty code I use to push a clean branch to one of my dev servers.
Use this to trigger the pull:
git push origin --delete staging ; git push origin master:staging
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 | |
| $tracking_branch = 'refs/heads/staging'; | |
| $source_root = '/path/to/git/root'; | |
| if( empty($_POST['payload']) ) | |
| return; | |
| $json = json_decode( $_POST['payload'], true ); | |
| if( empty($json) || empty($json['ref'] ) ) | |
| return; | |
| if( $json['ref'] != $tracking_branch || !empty($json['deleted']) ) | |
| return; | |
| if( !chdir($source_root) ) | |
| die( __FILE__ . ": Could not change to $source_root" ); | |
| $branch = trim(`git symbolic-ref -q HEAD`, " \n"); | |
| if( $branch != $tracking_branch ) | |
| die( __FILE__ . ": Current branch $branch differs from our staging branch $tracking_branch" ); | |
| $last = exec( 'git reset --hard HEAD && git pull -r --ff-only 2>&1', $output, $retval ); | |
| if( $retval ) | |
| error_log( __FILE__ . ": webhook output: " . implode($output, "\n") ); | |
| // EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment