Skip to content

Instantly share code, notes, and snippets.

@Rarst
Created March 3, 2020 12:25
Show Gist options
  • Select an option

  • Save Rarst/ebd43af5e2d76bdaf180c7dd76f0fb28 to your computer and use it in GitHub Desktop.

Select an option

Save Rarst/ebd43af5e2d76bdaf180c7dd76f0fb28 to your computer and use it in GitHub Desktop.

Revisions

  1. Rarst revised this gist Mar 3, 2020. No changes.
  2. Rarst created this gist Mar 3, 2020.
    17 changes: 17 additions & 0 deletions git-gc.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?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" );
    }
    }