Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
Last active December 12, 2015 00:08
Show Gist options
  • Select an option

  • Save jehoshua02/4681039 to your computer and use it in GitHub Desktop.

Select an option

Save jehoshua02/4681039 to your computer and use it in GitHub Desktop.
###################################################
# 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
<?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);
});
<?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