mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
Adding recursive repository scanning. Fixes #2
This commit is contained in:
@@ -49,14 +49,31 @@ class Client
|
|||||||
* @return array Found repositories, containing their name, path and description
|
* @return array Found repositories, containing their name, path and description
|
||||||
*/
|
*/
|
||||||
public function getRepositories($path)
|
public function getRepositories($path)
|
||||||
|
{
|
||||||
|
$repositories = $this->recurseDirectory($path);
|
||||||
|
|
||||||
|
if (!isset($repositories)) {
|
||||||
|
throw new \RuntimeException('There are no GIT repositories in ' . $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
sort($repositories);
|
||||||
|
|
||||||
|
return $repositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function recurseDirectory($path)
|
||||||
{
|
{
|
||||||
$dir = new \DirectoryIterator($path);
|
$dir = new \DirectoryIterator($path);
|
||||||
|
|
||||||
foreach ($dir as $file) {
|
foreach ($dir as $file) {
|
||||||
|
if ($file->isDot()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$isBare = file_exists($file->getPathname() . '/HEAD');
|
$isBare = file_exists($file->getPathname() . '/HEAD');
|
||||||
$isRepository = file_exists($file->getPathname() . '/.git/HEAD');
|
$isRepository = file_exists($file->getPathname() . '/.git/HEAD');
|
||||||
|
|
||||||
if ($file->isDir() && !$file->isDot() && $isRepository || $isBare) {
|
if ($file->isDir() && $isRepository || $isBare) {
|
||||||
if ($isBare) {
|
if ($isBare) {
|
||||||
$description = file_get_contents($file->getPathname() . '/description');
|
$description = file_get_contents($file->getPathname() . '/description');
|
||||||
} else {
|
} else {
|
||||||
@@ -64,15 +81,14 @@ class Client
|
|||||||
}
|
}
|
||||||
|
|
||||||
$repositories[] = array('name' => $file->getFilename(), 'path' => $file->getPathname(), 'description' => $description);
|
$repositories[] = array('name' => $file->getFilename(), 'path' => $file->getPathname(), 'description' => $description);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($file->isDir()) {
|
||||||
|
$repositories = $this->recurseDirectory($file->getPathname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($repositories)) {
|
|
||||||
throw new \RuntimeException('There are no GIT repositories in ' . $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
sort($repositories);
|
|
||||||
|
|
||||||
return $repositories;
|
return $repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user