mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-08 02:31:36 +02:00
fix: redirect to submodule instead of throwing 500 error when viewing submodule entry (#5267)
This commit is contained in:
parent
5e79b39654
commit
f7e119f2e7
2 changed files with 15 additions and 1 deletions
|
@ -1044,7 +1044,15 @@ func renderHomeCode(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if entry.IsDir() {
|
||||
if entry.IsSubModule() {
|
||||
subModuleURL, err := ctx.Repo.Commit.GetSubModule(entry.Name())
|
||||
if err != nil {
|
||||
HandleGitError(ctx, "Repo.Commit.GetSubModule", err)
|
||||
return
|
||||
}
|
||||
subModuleFile := git.NewSubModuleFile(ctx.Repo.Commit, subModuleURL, entry.ID.String())
|
||||
ctx.Redirect(subModuleFile.RefURL(setting.AppURL, ctx.Repo.Repository.FullName(), setting.SSH.Domain))
|
||||
} else if entry.IsDir() {
|
||||
renderDirectory(ctx)
|
||||
} else {
|
||||
renderFile(ctx, entry)
|
||||
|
|
|
@ -1426,6 +1426,12 @@ func TestRepoSubmoduleView(t *testing.T) {
|
|||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
htmlDoc.AssertElement(t, fmt.Sprintf(`tr[data-entryname="repo1"] a[href="%s"]`, u.JoinPath("/user2/repo1").String()), true)
|
||||
|
||||
// Check that a link to the submodule returns a redirect and that the redirect link is correct.
|
||||
req = NewRequest(t, "GET", "/"+repo.FullName()+"/src/branch/"+repo.DefaultBranch+"/repo1")
|
||||
resp = MakeRequest(t, req, http.StatusSeeOther)
|
||||
|
||||
assert.Equal(t, u.JoinPath("/user2/repo1").String(), resp.Header().Get("Location"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue