From 1cae7513d43bd9dd7d13ccfefb82fefa65670af1 Mon Sep 17 00:00:00 2001 From: Guillaume Zitta Date: Mon, 29 Jul 2013 18:00:37 +0200 Subject: [PATCH] contextual readme management --- src/GitList/Controller/TreeController.php | 2 +- src/GitList/Util/Repository.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/GitList/Controller/TreeController.php b/src/GitList/Controller/TreeController.php index 384b537..649545a 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 5f6c80c..89944fa 100644 --- a/src/GitList/Util/Repository.php +++ b/src/GitList/Util/Repository.php @@ -161,18 +161,21 @@ 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() ); } }