Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tree not found page #26570

Merged
merged 27 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9057b19
improve
yp05327 Aug 18, 2023
8126566
improve
yp05327 Aug 18, 2023
514f5f6
Update options/locale/locale_en-US.ini
yp05327 Aug 18, 2023
4f10f70
improve
yp05327 Aug 18, 2023
927b41a
Update modules/context/context_response.go
wxiaoguang Aug 18, 2023
1e6be71
improve
yp05327 Aug 18, 2023
99de298
improve
yp05327 Aug 21, 2023
56cfc57
improve
yp05327 Aug 22, 2023
b3a1ffd
Merge branch 'main' into improve-tree-not-found
yp05327 Sep 25, 2023
d532eab
support different ref type redirect
yp05327 Sep 25, 2023
ae103ab
improve
yp05327 Sep 25, 2023
8a12915
Merge branch 'main' into improve-tree-not-found
delvh Sep 27, 2023
842e41f
Update routers/web/repo/helper.go
yp05327 Sep 28, 2023
865742c
Update options/locale/locale_en-US.ini
yp05327 Sep 28, 2023
ea92ea2
Use the new `ctx.Locale.Tr` instead of `.locale.Tr`
delvh Sep 28, 2023
bb0fcf8
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
a04e9b8
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
9438a4c
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
01179ad
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
096262e
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
2491af3
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
ca53832
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 28, 2023
88a32c9
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 29, 2023
d3a9d96
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 29, 2023
871e47b
Merge branch 'main' into improve-tree-not-found
GiteaBot Sep 29, 2023
c682f0b
Fix lint
lunny Sep 29, 2023
36a8f2b
Merge branch 'main' into improve-tree-not-found
lunny Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ step2 = Step 2:

error = Error
error404 = The page you are trying to reach either <strong>does not exist</strong> or <strong>you are not authorized</strong> to view it.
go_back = Go Back

never = Never
unknown = Unknown
Expand Down Expand Up @@ -1007,6 +1008,8 @@ delete_preexisting_success = Deleted unadopted files in %s
blame_prior = View blame prior to this change
author_search_tooltip = Shows a maximum of 30 users

tree_path_not_found = Path %[1]s doesn't exist in branch %[2]s
delvh marked this conversation as resolved.
Show resolved Hide resolved

transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
transfer.reject = Reject Transfer
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func RefBlame(ctx *context.Context) {
// Get current entry user currently looking at.
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
return
}

Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
if !isNewFile {
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("GetTreeEntryByPath", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
return
}

Expand Down
10 changes: 10 additions & 0 deletions routers/web/repo/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
package repo

import (
"net/url"
"sort"

"code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
)

func MakeSelfOnTop(ctx *context.Context, users []*user.User) []*user.User {
Expand All @@ -21,3 +23,11 @@ func MakeSelfOnTop(ctx *context.Context, users []*user.User) []*user.User {
}
return users
}

func HandleGitError(ctx *context.Context, msg string, err error) {
if git.IsErrNotExist(err) {
ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found", ctx.Repo.TreePath, ctx.Repo.BranchName)
ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/branch/" + url.PathEscape(ctx.Repo.BranchName)
delvh marked this conversation as resolved.
Show resolved Hide resolved
}
ctx.NotFoundOrServerError(msg, git.IsErrNotExist, err)
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 5 additions & 5 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
}
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.SubTree", err)
return
}
allEntries, err := tree.ListEntries()
Expand Down Expand Up @@ -791,7 +791,7 @@ func LastCommit(ctx *context.Context) {
func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entries {
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.SubTree", err)
return nil
}

Expand All @@ -800,12 +800,12 @@ func renderDirectoryFiles(ctx *context.Context, timeout time.Duration) git.Entri
// Get current entry user currently looking at.
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
return nil
}

if !entry.IsDir() {
ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
return nil
}

Expand Down Expand Up @@ -971,7 +971,7 @@ func renderCode(ctx *context.Context) {
// Get current entry user currently looking at.
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
HandleGitError(ctx, "Repo.Commit.GetTreeEntryByPath", err)
return
}

Expand Down
5 changes: 4 additions & 1 deletion templates/status/404.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
{{if .IsRepo}}{{template "repo/header" .}}{{end}}
<div class="ui container center">
<p style="margin-top: 100px"><img src="{{AssetUrlPrefix}}/img/404.png" alt="404"></p>
<p>{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{.locale.Tr "error404" | Safe}}{{end}}</p>
{{if .NotFoundGoBackURL}}<a class="ui button green" href="{{.NotFoundGoBackURL}}">{{.locale.Tr "go_back"}}</a>{{end}}
delvh marked this conversation as resolved.
Show resolved Hide resolved

<div class="divider"></div>
<br>
<p>{{.locale.Tr "error404" | Safe}}</p>

{{if .ShowFooterVersion}}<p>{{.locale.Tr "admin.config.app_ver"}}: {{AppVer}}</p>{{end}}
</div>
</div>
Expand Down