From de57d7d489ec1b99f99abc13de07fa3c861b8b69 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Wed, 23 May 2012 03:31:21 -0300 Subject: [PATCH] Adding recursive repository scanning. Fixes #2 --- lib/Git/Client.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/Git/Client.php b/lib/Git/Client.php index 2cc44f6..e7a4ae0 100644 --- a/lib/Git/Client.php +++ b/lib/Git/Client.php @@ -49,14 +49,31 @@ class Client * @return array Found repositories, containing their name, path and description */ 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); foreach ($dir as $file) { + if ($file->isDot()) { + continue; + } + $isBare = file_exists($file->getPathname() . '/HEAD'); $isRepository = file_exists($file->getPathname() . '/.git/HEAD'); - if ($file->isDir() && !$file->isDot() && $isRepository || $isBare) { + if ($file->isDir() && $isRepository || $isBare) { if ($isBare) { $description = file_get_contents($file->getPathname() . '/description'); } else { @@ -64,15 +81,14 @@ class Client } $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; }