diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index b3d88b4..1f20220 100644 --- a/src/GitList/Controller/TreeController.php +++ b/src/GitList/Controller/TreeController.php @@ -41,7 +41,7 @@ class TreeController implements ControllerProviderInterface 'breadcrumbs' => $breadcrumbs, 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), - 'readme' => $app['util.repository']->getReadme($repository, $branch), + 'readme' => $app['util.repository']->getReadme($repository, $branch, $tree ? "$tree" : ""), )); })->assert('repo', $app['util.routing']->getRepositoryRegex()) ->assert('commitishPath', $app['util.routing']->getCommitishPathRegex()) diff --git a/src/GitList/Util/Repository.php b/src/GitList/Util/Repository.php index 1295276..d4db5a8 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -164,22 +164,26 @@ class Repository return false; } - public function getReadme($repository, $branch = null) + public function getReadme($repository, $branch = null, $path = "") { - $files = $repository->getTree($branch)->output(); if ($branch === null) { $branch = $repository->getHead(); } + if ($path != "") $path = "$path/"; + + $files = $repository->getTree($path != "" ? "$branch:$path" : $branch)->output(); + foreach ($files as $file) { if (preg_match('/^readme*/i', $file['name'])) { return array( 'filename' => $file['name'], - 'content' => $repository->getBlob("$branch:\"{$file['name']}\"")->output() + 'content' => $repository->getBlob("$branch:\"$path{$file['name']}\"")->output() ); } } - + // No contextual readme, try to catch the main one if we are in deeper context + if ($path != "") return $this->getReadme($repository, $branch, ""); return array(); }