@@ -12,13 +12,13 @@ import org.eclipse.jgit.treewalk.TreeWalk
12
12
import scala .language .implicitConversions
13
13
14
14
class PagesController
15
- extends ControllerBase
15
+ extends PagesControllerBase
16
16
with AccountService
17
17
with RepositoryService
18
18
with ReferrerAuthenticator
19
19
20
- trait PagesControllerBase {
21
- self : ControllerBase with AccountService with RepositoryService with ReferrerAuthenticator =>
20
+ trait PagesControllerBase extends ControllerBase {
21
+ self : AccountService with RepositoryService with ReferrerAuthenticator =>
22
22
23
23
val PAGES_BRANCH = " gh-pages"
24
24
@@ -34,7 +34,7 @@ trait PagesControllerBase {
34
34
objectId match {
35
35
case Some ((path0, objId)) =>
36
36
// redirect [owner/repo/pages/path] -> [owner/repo/pages/path/]
37
- if (path0 != path && path0.startsWith (path) && ! path.endsWith( " / " )) {
37
+ if (shouldRedirect (path, path0 )) {
38
38
redirect(s " / ${repository.owner}/ ${repository.name}/pages/ $path/ " )
39
39
} else {
40
40
JGitUtil .getObjectLoaderFromId(git, objId) { loader =>
@@ -54,6 +54,9 @@ trait PagesControllerBase {
54
54
redirect(s " / ${repository.owner}/ ${repository.name}/pages/ " )
55
55
})
56
56
57
+ def shouldRedirect (path : String , path0 : String ) =
58
+ ! isRoot(path) && path0 != path && path0.startsWith(path) && ! path.endsWith(" /" )
59
+
57
60
def getPathIndexObjectId (git : Git , path : String , revCommit : RevCommit ) = {
58
61
getPathObjectId0(git, path, revCommit)
59
62
.orElse(getPathObjectId0(git, appendPath(path, " index.html" ), revCommit))
@@ -65,11 +68,13 @@ trait PagesControllerBase {
65
68
}
66
69
67
70
def appendPath (base : String , suffix : String ): String = {
68
- if (base == " " ) suffix
71
+ if (isRoot( base) ) suffix
69
72
else if (base.endsWith(" /" )) base + suffix
70
73
else base + " /" + suffix
71
74
}
72
75
76
+ def isRoot (path : String ) = path == " "
77
+
73
78
// copy&paste from RepositoryViewerControllerBase
74
79
private def getPathObjectId (git : Git , path : String , revCommit : RevCommit ): Option [ObjectId ] = {
75
80
@ scala.annotation.tailrec
0 commit comments