Last active
December 12, 2015 00:08
-
-
Save jehoshua02/4681039 to your computer and use it in GitHub Desktop.
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
| ################################################### | |
| # WHITELISTED FILES | |
| # | |
| # Because we found so much garbage in here | |
| # that we cannot tell what is important, and | |
| # because we don't want to track garbage, we | |
| # have the `include_log.php` script automatically | |
| # append included files here. | |
| # | |
| # DO NOT EDIT BELOW -- Put custom .gitignores above | |
| ################################################### | |
| # ignore everything | |
| * | |
| # ... except directories, because ignoring them will | |
| # ignore everything inside them | |
| !*/ | |
| # ... now whitelist 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 | |
| /** | |
| * Register a function to whitelist included files before execution ends | |
| * | |
| * Assumes this script is in same directory as .gitignore. Adds whitelists to | |
| * .gitignore for every file included. Doesn't add the same whitelist twice | |
| */ | |
| register_shutdown_function(function () { | |
| $gitignoreFile = __DIR__ . '/.gitignore'; | |
| $gitignores = explode("\n", file_get_contents($gitignoreFile)); | |
| $includes = array_unique(get_included_files()); | |
| $includeToWhitelist = function ($file) { | |
| return '!' . str_replace(__DIR__, '', $file); | |
| }; | |
| $whitelists = array_diff(array_map($includeToWhitelist, $includes), $gitignores); | |
| file_put_contents($gitignoreFile, implode("\n", $whitelists), FILE_APPEND); | |
| }); |
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 | |
| include __DIR__ . '/gitignore_whitelist_includes.php'; | |
| // some code here ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment