Last active
August 29, 2015 14:17
-
-
Save dprevite/5a5aabb9b7708b0a9548 to your computer and use it in GitHub Desktop.
Search computer for all git repos and add lolcommits hook to all the post-commit files
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 | |
$contents = '#!/bin/sh' . PHP_EOL . '/Users/dprevite/Dropbox/lolcommits/post-commit' . PHP_EOL; | |
// Get the home directory | |
$homeDir = `echo ~`; | |
$homeDir = trim($homeDir); | |
// Find all the existing post commit files | |
echo 'Finding all of the git repositories in your home directory, ' . $homeDir . PHP_EOL; | |
$matches = `locate .git/hooks/`; | |
$matches = explode(PHP_EOL, trim($matches)); | |
$directories = []; | |
// Loop through each match and get an array of directories | |
foreach ($matches as $directory) { | |
$directories[] = dirname($directory); | |
} | |
// We only want 1 entry per directory | |
$directories = array_unique($directories); | |
// Loop through the directories creating hooks | |
foreach ($directories as $directory) { | |
// We don't want to mess up composer directories | |
if (strpos($directory, '/vendor/') !== FALSE) { | |
continue; | |
} | |
// Only update stuff in the users home directory | |
if (strpos($directory, $homeDir) === FALSE) { | |
continue; | |
} | |
echo PHP_EOL . PHP_EOL . PHP_EOL; | |
echo 'Checking for hook in ' . $directory . '...' . PHP_EOL; | |
if (!file_exists($directory . '/post-commit')) { | |
echo 'No post commit file, creating' . PHP_EOL; | |
touch($directory . '/post-commit'); | |
chmod($directory . '/post-commit', 0777); | |
} | |
echo 'Putting hooks into ' . $directory . '/post-commit' . PHP_EOL; | |
file_put_contents($directory . '/post-commit', $contents); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment