@@ -12,13 +12,13 @@ import org.eclipse.jgit.treewalk.TreeWalk
1212import scala .language .implicitConversions
1313
1414class PagesController
15- extends ControllerBase
15+ extends PagesControllerBase
1616 with AccountService
1717 with RepositoryService
1818 with ReferrerAuthenticator
1919
20- trait PagesControllerBase {
21- self : ControllerBase with AccountService with RepositoryService with ReferrerAuthenticator =>
20+ trait PagesControllerBase extends ControllerBase {
21+ self : AccountService with RepositoryService with ReferrerAuthenticator =>
2222
2323 val PAGES_BRANCH = " gh-pages"
2424
@@ -34,7 +34,7 @@ trait PagesControllerBase {
3434 objectId match {
3535 case Some ((path0, objId)) =>
3636 // redirect [owner/repo/pages/path] -> [owner/repo/pages/path/]
37- if (path0 != path && path0.startsWith (path) && ! path.endsWith( " / " )) {
37+ if (shouldRedirect (path, path0 )) {
3838 redirect(s " / ${repository.owner}/ ${repository.name}/pages/ $path/ " )
3939 } else {
4040 JGitUtil .getObjectLoaderFromId(git, objId) { loader =>
@@ -54,6 +54,9 @@ trait PagesControllerBase {
5454 redirect(s " / ${repository.owner}/ ${repository.name}/pages/ " )
5555 })
5656
57+ def shouldRedirect (path : String , path0 : String ) =
58+ ! isRoot(path) && path0 != path && path0.startsWith(path) && ! path.endsWith(" /" )
59+
5760 def getPathIndexObjectId (git : Git , path : String , revCommit : RevCommit ) = {
5861 getPathObjectId0(git, path, revCommit)
5962 .orElse(getPathObjectId0(git, appendPath(path, " index.html" ), revCommit))
@@ -65,11 +68,13 @@ trait PagesControllerBase {
6568 }
6669
6770 def appendPath (base : String , suffix : String ): String = {
68- if (base == " " ) suffix
71+ if (isRoot( base) ) suffix
6972 else if (base.endsWith(" /" )) base + suffix
7073 else base + " /" + suffix
7174 }
7275
76+ def isRoot (path : String ) = path == " "
77+
7378 // copy&paste from RepositoryViewerControllerBase
7479 private def getPathObjectId (git : Git , path : String , revCommit : RevCommit ): Option [ObjectId ] = {
7580 @ scala.annotation.tailrec
0 commit comments