Last active
October 20, 2020 13:38
-
-
Save tg666/faa404b0b98bbc7c7ef7af93993afd43 to your computer and use it in GitHub Desktop.
Dumps duplicated directories tracked by git. Dependent on a package `symfony/process`.
This file contains 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 | |
require __DIR__ . '/../vendor/autoload.php'; | |
$duplicates = (static function (array $paths) { | |
$directories = [[]]; | |
foreach ($paths as $path) { | |
$directories[] = (static function (string $path) { | |
$process = Symfony\Component\Process\Process::fromShellCommandline('git ls-tree -r --name-only HEAD "$TREE_PATH"'); | |
$directories = []; | |
$process->run(static function (string $type, string $output) use (&$directories) { | |
if (Symfony\Component\Process\Process::OUT !== $type) { | |
throw new RuntimeException('Can not read a git tree.'); | |
} | |
$directories = array_merge( | |
$directories, | |
array_unique( | |
array_map(static function (string $path) { | |
return dirname($path); | |
}, explode("\n", $output)) | |
) | |
); | |
}, ['TREE_PATH' => $path]); | |
return $directories; | |
})($path); | |
} | |
$directories = array_unique(array_merge(...$directories)); | |
$duplicates = []; | |
foreach ($directories as $directory) { | |
$duplicates[strtolower($directory)][] = $directory; | |
} | |
return array_values(array_filter($duplicates, static function (array $dirs) { | |
return 1 < count($dirs); | |
})); | |
})([ | |
__DIR__ . '/../src', | |
__DIR__ . '/../extensions', | |
]); | |
var_dump($duplicates); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment