Skip to content

Instantly share code, notes, and snippets.

@eznix86
Last active December 26, 2019 07:30
Show Gist options
  • Save eznix86/6d84c95af57c3dad92a83b764e56ad5b to your computer and use it in GitHub Desktop.
Save eznix86/6d84c95af57c3dad92a83b764e56ad5b to your computer and use it in GitHub Desktop.
command to to add a pre-push script in git
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