Skip to content

Instantly share code, notes, and snippets.

@morrisonlevi
Last active December 30, 2015 21:19
Show Gist options
  • Save morrisonlevi/7886473 to your computer and use it in GitHub Desktop.
Save morrisonlevi/7886473 to your computer and use it in GitHub Desktop.
A git hook that won't let you commit on Tuesday or Wednesday in preparation for BC Break Thursday.
#!/usr/bin/env php
<?php
/**
* @installation Copy this file to .git/hooks/pre-commit if
* you do not have any pre-commit hooks.
* @policy Enforce BC Break Thursday
* @desc If we are within 2 days of Thursday, do not
* accept commits.
*/
// Work-around for ini-less PHP 5.4+ installs which require a
// timezone to be set.
date_default_timezone_set(ini_get('date.timezone') ?: 'UTC');
$today = new DateTime();
if ($today->format('l') === 'Thursday') {
// accept
exit(0);
}
$nextThursday = new DateTime("next Thursday");
$diffTillThursday = $nextThursday->diff($today);
if (((int)$diffTillThursday->format("%d")) <= 2) {
//reject
// use PHP_EOL for that (weird) Windows guy
fprintf(STDERR, "Error: you must wait for BC Break Thursday%s", PHP_EOL);
exit(1);
}
// accept
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment