Created
March 16, 2015 21:07
-
-
Save jtsternberg/08bf493feee6bc1449bb to your computer and use it in GitHub Desktop.
Run dockunit (but could do with phpunit or any other command) if any php files have changed and are about to be pushed. Rename to `pre-push` and put in the `.git/hooks/` directory.
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
#!/usr/bin/php | |
<?php | |
$lines = file_get_contents( 'php://stdin', 'r' ); | |
if ( empty( $lines ) ) { | |
exit( 0 ); | |
} | |
$lines = explode( "\n", $lines ); | |
$lines = explode( ' ', $lines[0] ); | |
exec( 'git diff --name-only '. $lines[1] .' '. $lines[3], $files ); | |
$do_tests = false; | |
if ( ! empty( $files ) ) { | |
foreach ( $files as $file ) { | |
$parts = explode( '.', $file ); | |
$ext = end( $parts ); | |
if ( 'php' == $ext ) { | |
$do_tests = true; | |
} | |
} | |
} | |
if ( ! $do_tests ) { | |
exit( 0 ); | |
} | |
echo "Run Dockunit\n"; | |
$projectName = basename( getcwd() ); | |
exec( 'dockunit', $output, $returnCode ); | |
if ( 0 !== $returnCode ) { | |
$minimalTestSummary = array_pop( $output ); | |
printf( "Test suite for %s failed: ", $projectName ); | |
printf( "(%s) %s%2\$s", $minimalTestSummary, PHP_EOL ); | |
printf( "ABORTING PUSH!\n" ); | |
exit( 1 ); | |
} | |
printf( "All tests for %s passed.%s%2\$s", $projectName, PHP_EOL ); | |
exit( 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment