Created
March 3, 2020 12:25
-
-
Save Rarst/ebd43af5e2d76bdaf180c7dd76f0fb28 to your computer and use it in GitHub Desktop.
Find and garbage collect all Git repositories in path `php git-gc.php /path/to/walk`.
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 | |
declare( strict_types=1 ); | |
$path = $argv[1]; | |
$iterator = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator( $path ), | |
RecursiveIteratorIterator::SELF_FIRST | |
); | |
/** @var SplFileInfo $file */ | |
foreach ( $iterator as $file ) { | |
if ( $file->isDir() && '.git' === $file->getBasename() ) { | |
echo $file->getPath() . "\n"; | |
exec( "cd {$file->getPath()} && git gc --aggressive" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment