Last active
August 29, 2015 14:17
Revisions
-
dprevite revised this gist
Apr 16, 2015 . 1 changed file with 30 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,17 @@ <?php /** * Search forward starting from end minus needle length characters * * @param string $haystack The string to search within * @param string $needle The string to search for * * @return boolean **/ function endsWith($haystack, $needle) { return $needle === '' || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE); } $contents = '#!/bin/sh' . PHP_EOL . '/Users/dprevite/Dropbox/lolcommits/post-commit' . PHP_EOL; // Get the home directory @@ -7,14 +20,20 @@ // 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 hook directories foreach ($matches as $directory) { $directory = dirname($directory); if (!endsWith($directory, '/hooks')) { $directory .= '/hooks'; } $directories[] = $directory; } // We only want 1 entry per directory @@ -24,16 +43,22 @@ foreach ($directories as $directory) { // We don't want to mess up composer directories if (strpos($directory, '/vendor/') !== FALSE) { echo 'Skipping ' . $directory . ' because it is a vendor directory.' . PHP_EOL; continue; } // Weird thing for coderobot.io storage dirs if (strpos($directory, '/storage/') !== FALSE) { echo 'Skipping ' . $directory . ' because it is a storage directory.' . PHP_EOL; continue; } // Only update stuff in the users home directory if (strpos($directory, $homeDir) === FALSE) { echo 'Skipping ' . $directory . ' because it isn\'t in the users home directory.' . PHP_EOL; continue; } echo 'Checking for hook in ' . $directory . '...' . PHP_EOL; if (!file_exists($directory . '/post-commit')) { echo 'No post commit file, creating' . PHP_EOL; -
dprevite revised this gist
Mar 29, 2015 . 1 changed file with 38 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,46 @@ <?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); } -
dprevite created this gist
Mar 29, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <?php $contents = '#!/bin/sh' . PHP_EOL . './Users/dprevite/Dropbox/lolcommits/post-commit' . PHP_EOL; // Find all the existing post commit files $gitPostCommitFiles = `locate post-commit`; $gitPostCommitFiles = explode(PHP_EOL, trim($gitPostCommitFiles)); // Loop through each match foreach ($gitPostCommitFiles as $file) { if (!file_exists(dirname($file) . '/post-commit')) { echo 'No post commit file, creating' . PHP_EOL; touch(dirname($file) . '/post-commit'); chmod(dirname($file) . '/post-commit', 0777); } echo 'Putting hooks into ' . dirname($file) . '/post-commit' . PHP_EOL; file_put_contents(dirname($file) . '/post-commit', $contents); }