Last active
December 26, 2019 07:30
-
-
Save eznix86/6d84c95af57c3dad92a83b764e56ad5b to your computer and use it in GitHub Desktop.
command to to add a pre-push script in git
This file contains 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
cat <<EOF >> .git/hooks/pre-push | |
#!/usr/bin/php | |
<?php | |
function run(\$title, \$command) { | |
echo "+ Starting \$title".PHP_EOL; | |
exec("\$command", \$output, \$returnCode); | |
if ($returnCode !== 0) { | |
foreach (\$output as \$line) { | |
echo "\$line\n"; | |
} | |
echo PHP_EOL; | |
echo PHP_EOL; | |
printf("- [FAILED] %s - ABORTING PUSH!\n", strtoupper(\$title)); | |
exit(1); // git halts | |
} | |
printf("- [PASSED] %s\n", \$title); | |
} | |
run("tests cs", "docker-compose exec -T web make tests-cs"); | |
run("unit tests", "docker-compose exec -T web make tests-unit"); | |
exit(0); // git continues | |
EOF | |
chmod +x .git/hooks/pre-push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment