From 9057b1903c6b338b859676d84cea17d70fd35c2d Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 18 Aug 2023 02:47:56 +0000
Subject: [PATCH 01/14] improve
---
modules/context/context_response.go | 2 ++
options/locale/locale_en-US.ini | 3 +++
templates/status/404.tmpl | 5 +++++
3 files changed, 10 insertions(+)
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 5729865561e52..0d6a27aaaf484 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -136,6 +137,7 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
ctx.Data["Title"] = "Page Not Found"
+ ctx.Data["IsTreeNotFound"] = git.IsErrNotExist(logErr)
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
}
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 0bfe1eac75dd6..429e5457687da 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1007,6 +1007,9 @@ 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_not_found = The %s branch of %s does not contain the path %s
+return_to_repository = Return to the repository
+
transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
transfer.reject = Reject Transfer
diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl
index 382f22520b088..0dc05dc95d9d9 100644
--- a/templates/status/404.tmpl
+++ b/templates/status/404.tmpl
@@ -5,8 +5,13 @@
+ {{if and .IsRepo .IsTreeNotFound}}
+ {{.locale.Tr "repo.tree_not_found" .BranchName .RepoName .TreePath | Safe}}
+ {{.locale.Tr "repo.return_to_repository"}}
+ {{else}}
{{.locale.Tr "error404" | Safe}}
{{if .ShowFooterVersion}}{{.locale.Tr "admin.config.app_ver"}}: {{AppVer}}
{{end}}
+ {{end}}
{{template "base/footer" .}}
From 8126566acb8c33dc97cbaa8bfb443460cc35a1fb Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 18 Aug 2023 06:20:34 +0000
Subject: [PATCH 02/14] improve
---
modules/context/context_response.go | 6 +++++-
options/locale/locale_en-US.ini | 4 ++--
templates/status/404.tmpl | 10 ++++------
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 0d6a27aaaf484..9c8a03a36cc23 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -137,7 +137,11 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
ctx.Data["Title"] = "Page Not Found"
- ctx.Data["IsTreeNotFound"] = git.IsErrNotExist(logErr)
+
+ if git.IsErrNotExist(logErr) {
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_not_found", ctx.Repo.BranchName, ctx.Repo.Repository.Name, ctx.Repo.TreePath)
+ ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/branch/" + url.PathEscape(ctx.Repo.BranchName)
+ }
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
}
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 429e5457687da..19d393a0a8a77 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -112,6 +112,7 @@ step2 = Step 2:
error = Error
error404 = The page you are trying to reach either does not exist or you are not authorized to view it.
+back = Back
never = Never
unknown = Unknown
@@ -1007,8 +1008,7 @@ 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_not_found = The %s branch of %s does not contain the path %s
-return_to_repository = Return to the repository
+tree_not_found = The %s branch of %s does not contain the path %s
transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl
index 0dc05dc95d9d9..3eac2b6f36bba 100644
--- a/templates/status/404.tmpl
+++ b/templates/status/404.tmpl
@@ -3,15 +3,13 @@
{{if .IsRepo}}{{template "repo/header" .}}{{end}}
+
{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{.locale.Tr "error404" | Safe}}{{end}}
+ {{if .NotFoundGoBackURL}}
{{.locale.Tr "back"}}{{end}}
+
- {{if and .IsRepo .IsTreeNotFound}}
-
{{.locale.Tr "repo.tree_not_found" .BranchName .RepoName .TreePath | Safe}}
-
{{.locale.Tr "repo.return_to_repository"}}
- {{else}}
-
{{.locale.Tr "error404" | Safe}}
+
{{if .ShowFooterVersion}}
{{.locale.Tr "admin.config.app_ver"}}: {{AppVer}}
{{end}}
- {{end}}
{{template "base/footer" .}}
From 514f5f6b33a9e6ac79057a12f5d9442f2046193c Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 18 Aug 2023 16:00:46 +0900
Subject: [PATCH 03/14] Update options/locale/locale_en-US.ini
Co-authored-by: wxiaoguang
---
options/locale/locale_en-US.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 19d393a0a8a77..624fdd1e6e53b 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1008,7 +1008,7 @@ 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_not_found = The %s branch of %s does not contain the path %s
+tree_path_not_found = Path %[1]s doesn't exist in branch %[2]s
transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
From 4f10f7043ea8b2d307a36e5027efe723b1013697 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 18 Aug 2023 07:05:44 +0000
Subject: [PATCH 04/14] improve
---
modules/context/context_response.go | 2 +-
options/locale/locale_en-US.ini | 2 +-
templates/status/404.tmpl | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 9c8a03a36cc23..28f7653338e75 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -139,7 +139,7 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
ctx.Data["Title"] = "Page Not Found"
if git.IsErrNotExist(logErr) {
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_not_found", ctx.Repo.BranchName, ctx.Repo.Repository.Name, ctx.Repo.TreePath)
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found", ctx.Repo.BranchName, ctx.Repo.Repository.Name, ctx.Repo.TreePath)
ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/branch/" + url.PathEscape(ctx.Repo.BranchName)
}
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 624fdd1e6e53b..56f1f436609c7 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -112,7 +112,7 @@ step2 = Step 2:
error = Error
error404 = The page you are trying to reach either does not exist or you are not authorized to view it.
-back = Back
+go_back = Go Back
never = Never
unknown = Unknown
diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl
index 3eac2b6f36bba..f8376d7e44e53 100644
--- a/templates/status/404.tmpl
+++ b/templates/status/404.tmpl
@@ -4,7 +4,7 @@
{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{.locale.Tr "error404" | Safe}}{{end}}
- {{if .NotFoundGoBackURL}}
{{.locale.Tr "back"}}{{end}}
+ {{if .NotFoundGoBackURL}}
{{.locale.Tr "go_back"}}{{end}}
From 927b41ae40abd9899ca4aad15ec060387b1b7952 Mon Sep 17 00:00:00 2001
From: wxiaoguang
Date: Fri, 18 Aug 2023 15:09:20 +0800
Subject: [PATCH 05/14] Update modules/context/context_response.go
---
modules/context/context_response.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 28f7653338e75..3ac06fd2cf0dc 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -139,7 +139,7 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
ctx.Data["Title"] = "Page Not Found"
if git.IsErrNotExist(logErr) {
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found", ctx.Repo.BranchName, ctx.Repo.Repository.Name, ctx.Repo.TreePath)
+ 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)
}
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
From 1e6be71f1a514eda2893b622d1c4d34f2ccc5aee Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Fri, 18 Aug 2023 07:15:08 +0000
Subject: [PATCH 06/14] improve
---
modules/context/context_response.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 3ac06fd2cf0dc..6023edc402175 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -138,8 +138,8 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
ctx.Data["Title"] = "Page Not Found"
- if git.IsErrNotExist(logErr) {
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found", ctx.Repo.TreePath, ctx.Repo.BranchName)
+ if ctx.Repo != nil && git.IsErrNotExist(logErr) {
+ 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)
}
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
From 99de298fa491b9f6423c70682914c547519dd804 Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Mon, 21 Aug 2023 04:09:57 +0000
Subject: [PATCH 07/14] improve
---
modules/context/context_response.go | 6 ------
routers/web/repo/blame.go | 2 +-
routers/web/repo/editor.go | 2 +-
routers/web/repo/helper.go | 10 ++++++++++
routers/web/repo/view.go | 10 +++++-----
5 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/modules/context/context_response.go b/modules/context/context_response.go
index 6023edc402175..5729865561e52 100644
--- a/modules/context/context_response.go
+++ b/modules/context/context_response.go
@@ -16,7 +16,6 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
- "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -137,11 +136,6 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
ctx.Data["Title"] = "Page Not Found"
-
- if ctx.Repo != nil && git.IsErrNotExist(logErr) {
- 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)
- }
ctx.HTML(http.StatusNotFound, base.TplName("status/404"))
}
diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go
index b1cb42297c1a6..73b54fb6b6686 100644
--- a/routers/web/repo/blame.go
+++ b/routers/web/repo/blame.go
@@ -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
}
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index b053e3c63f4a7..3fa32522d64b4 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -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
}
diff --git a/routers/web/repo/helper.go b/routers/web/repo/helper.go
index fb5ada1bdb476..53e5cc6b1fdc3 100644
--- a/routers/web/repo/helper.go
+++ b/routers/web/repo/helper.go
@@ -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 {
@@ -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)
+ }
+ ctx.NotFoundOrServerError(msg, git.IsErrNotExist, err)
+}
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 15c85f6427cec..71a6e7aad0422 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -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()
@@ -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
}
@@ -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
}
@@ -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
}
From 56cfc5773c74d185fa1eae234451a4061f3d126d Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Tue, 22 Aug 2023 04:31:30 +0000
Subject: [PATCH 08/14] improve
---
routers/web/repo/helper.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/routers/web/repo/helper.go b/routers/web/repo/helper.go
index 53e5cc6b1fdc3..84df3f9980df9 100644
--- a/routers/web/repo/helper.go
+++ b/routers/web/repo/helper.go
@@ -28,6 +28,8 @@ 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)
+ ctx.NotFound(msg, err)
+ } else {
+ ctx.ServerError(msg, err)
}
- ctx.NotFoundOrServerError(msg, git.IsErrNotExist, err)
}
From d532eabeed6a41f2bbea7d834f6d3c386e79878c Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Mon, 25 Sep 2023 02:37:45 +0000
Subject: [PATCH 09/14] support different ref type redirect
---
options/locale/locale_en-US.ini | 4 +++-
routers/web/repo/helper.go | 13 +++++++++++--
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 1ce01bf098997..97942eb74c1e2 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1013,7 +1013,9 @@ blame.ignore_revs = Ignoring revisions in .git-blame-ignore-revs.git-blame-ignore-revs.
author_search_tooltip = Shows a maximum of 30 users
-tree_path_not_found = Path %[1]s doesn't exist in branch %[2]s
+tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s
+tree_path_not_found_tag = Path %[1]s doesn't exist in tag %[2]s
+tree_path_not_found_commit = Path %[1]s doesn't exist in commit %[2]s
transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
diff --git a/routers/web/repo/helper.go b/routers/web/repo/helper.go
index bbae3fa2d52b9..af6c14f7a48fd 100644
--- a/routers/web/repo/helper.go
+++ b/routers/web/repo/helper.go
@@ -26,8 +26,17 @@ func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
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)
+ switch {
+ case ctx.Repo.IsViewBranch:
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_branch", ctx.Repo.TreePath, ctx.Repo.RefName)
+ ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/branch/" + url.PathEscape(ctx.Repo.RefName)
+ case ctx.Repo.IsViewTag:
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_tag", ctx.Repo.TreePath, ctx.Repo.RefName)
+ ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/tag/" + url.PathEscape(ctx.Repo.RefName)
+ case ctx.Repo.IsViewCommit:
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_commit", ctx.Repo.TreePath, ctx.Repo.RefName)
+ ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/commit/" + url.PathEscape(ctx.Repo.RefName)
+ }
ctx.NotFound(msg, err)
} else {
ctx.ServerError(msg, err)
From ae103ab1a39a42d505eaed11a4765a05967f78fa Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Mon, 25 Sep 2023 02:56:44 +0000
Subject: [PATCH 10/14] improve
---
options/locale/locale_en-US.ini | 4 +---
routers/web/repo/helper.go | 12 ++++++------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 97942eb74c1e2..65a5ae95688c6 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1013,9 +1013,7 @@ blame.ignore_revs = Ignoring revisions in .git-blame-ignore-revs.git-blame-ignore-revs.
author_search_tooltip = Shows a maximum of 30 users
-tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s
-tree_path_not_found_tag = Path %[1]s doesn't exist in tag %[2]s
-tree_path_not_found_commit = Path %[1]s doesn't exist in commit %[2]s
+tree_path_not_found = Path %[1]s doesn't exist in %[2]s %[3]s
transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
diff --git a/routers/web/repo/helper.go b/routers/web/repo/helper.go
index af6c14f7a48fd..5ec66e6818244 100644
--- a/routers/web/repo/helper.go
+++ b/routers/web/repo/helper.go
@@ -26,17 +26,17 @@ func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
func HandleGitError(ctx *context.Context, msg string, err error) {
if git.IsErrNotExist(err) {
+ refType := ""
switch {
case ctx.Repo.IsViewBranch:
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_branch", ctx.Repo.TreePath, ctx.Repo.RefName)
- ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/branch/" + url.PathEscape(ctx.Repo.RefName)
+ refType = "branch"
case ctx.Repo.IsViewTag:
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_tag", ctx.Repo.TreePath, ctx.Repo.RefName)
- ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/tag/" + url.PathEscape(ctx.Repo.RefName)
+ refType = "tag"
case ctx.Repo.IsViewCommit:
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_commit", ctx.Repo.TreePath, ctx.Repo.RefName)
- ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/commit/" + url.PathEscape(ctx.Repo.RefName)
+ refType = "commit"
}
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found", ctx.Repo.TreePath, refType, url.PathEscape(ctx.Repo.RefName))
+ ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/" + refType + "/" + url.PathEscape(ctx.Repo.RefName)
ctx.NotFound(msg, err)
} else {
ctx.ServerError(msg, err)
From 842e41f230fad7730f57248ef67955de293ad3ca Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 28 Sep 2023 11:03:46 +0900
Subject: [PATCH 11/14] Update routers/web/repo/helper.go
Co-authored-by: delvh
---
routers/web/repo/helper.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/routers/web/repo/helper.go b/routers/web/repo/helper.go
index 5ec66e6818244..c502a45314f39 100644
--- a/routers/web/repo/helper.go
+++ b/routers/web/repo/helper.go
@@ -35,7 +35,7 @@ func HandleGitError(ctx *context.Context, msg string, err error) {
case ctx.Repo.IsViewCommit:
refType = "commit"
}
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found", ctx.Repo.TreePath, refType, url.PathEscape(ctx.Repo.RefName))
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_" + refType, ctx.Repo.TreePath, url.PathEscape(ctx.Repo.RefName))
ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/" + refType + "/" + url.PathEscape(ctx.Repo.RefName)
ctx.NotFound(msg, err)
} else {
From 865742cb9580034e077a9002c518ecdb19f1928f Mon Sep 17 00:00:00 2001
From: yp05327 <576951401@qq.com>
Date: Thu, 28 Sep 2023 11:03:55 +0900
Subject: [PATCH 12/14] Update options/locale/locale_en-US.ini
Co-authored-by: delvh
---
options/locale/locale_en-US.ini | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index eb493d93e87ed..c0d3224020e62 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1013,7 +1013,9 @@ blame.ignore_revs = Ignoring revisions in .git-blame-ignore-revs.git-blame-ignore-revs.
author_search_tooltip = Shows a maximum of 30 users
-tree_path_not_found = Path %[1]s doesn't exist in %[2]s %[3]s
+tree_path_not_found_commit = Path %[1]s doesn't exist in commit %[2]s
+tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s
+tree_path_not_found_tag = Path %[1]s doesn't exist in tag %[2]s
transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
From ea92ea26abdca4bce728af0fdf66b570d6608241 Mon Sep 17 00:00:00 2001
From: delvh
Date: Thu, 28 Sep 2023 10:22:49 +0200
Subject: [PATCH 13/14] Use the new `ctx.Locale.Tr` instead of `.locale.Tr`
---
templates/status/404.tmpl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/templates/status/404.tmpl b/templates/status/404.tmpl
index 0033d125dffea..74bb8762bd3e9 100644
--- a/templates/status/404.tmpl
+++ b/templates/status/404.tmpl
@@ -3,8 +3,8 @@
{{if .IsRepo}}{{template "repo/header" .}}{{end}}
-
{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{.locale.Tr "error404" | Safe}}{{end}}
- {{if .NotFoundGoBackURL}}
{{.locale.Tr "go_back"}}{{end}}
+
{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{ctx.Locale.Tr "error404" | Safe}}{{end}}
+ {{if .NotFoundGoBackURL}}
{{ctx.Locale.Tr "go_back"}}{{end}}
From c682f0b2e833882078c7b3f0fe3602a627f4ce2e Mon Sep 17 00:00:00 2001
From: Lunny Xiao
Date: Fri, 29 Sep 2023 15:10:32 +0800
Subject: [PATCH 14/14] Fix lint
---
routers/web/repo/helper.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/routers/web/repo/helper.go b/routers/web/repo/helper.go
index c502a45314f39..a98abe566f843 100644
--- a/routers/web/repo/helper.go
+++ b/routers/web/repo/helper.go
@@ -35,7 +35,7 @@ func HandleGitError(ctx *context.Context, msg string, err error) {
case ctx.Repo.IsViewCommit:
refType = "commit"
}
- ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_" + refType, ctx.Repo.TreePath, url.PathEscape(ctx.Repo.RefName))
+ ctx.Data["NotFoundPrompt"] = ctx.Locale.Tr("repo.tree_path_not_found_"+refType, ctx.Repo.TreePath, url.PathEscape(ctx.Repo.RefName))
ctx.Data["NotFoundGoBackURL"] = ctx.Repo.RepoLink + "/src/" + refType + "/" + url.PathEscape(ctx.Repo.RefName)
ctx.NotFound(msg, err)
} else {