loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: handle viewing a submodule entry (#7261)

- When trying to view a submodule directory via the normal `/src/branch/` path, generate a redirect link to the submodule location.
- Resolves forgejo/forgejo#5267

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7261
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Gnarwhal <git.aspect893@passmail.net>
Co-committed-by: Gnarwhal <git.aspect893@passmail.net>

authored by

Gnarwhal
Gnarwhal
and committed by
Gusted
d28a64e5 77b02755

+15 -1
+9 -1
routers/web/repo/view.go
··· 1044 1044 return 1045 1045 } 1046 1046 1047 - if entry.IsDir() { 1047 + if entry.IsSubModule() { 1048 + subModuleURL, err := ctx.Repo.Commit.GetSubModule(entry.Name()) 1049 + if err != nil { 1050 + HandleGitError(ctx, "Repo.Commit.GetSubModule", err) 1051 + return 1052 + } 1053 + subModuleFile := git.NewSubModuleFile(ctx.Repo.Commit, subModuleURL, entry.ID.String()) 1054 + ctx.Redirect(subModuleFile.RefURL(setting.AppURL, ctx.Repo.Repository.FullName(), setting.SSH.Domain)) 1055 + } else if entry.IsDir() { 1048 1056 renderDirectory(ctx) 1049 1057 } else { 1050 1058 renderFile(ctx, entry)
+6
tests/integration/repo_test.go
··· 1426 1426 1427 1427 htmlDoc := NewHTMLParser(t, resp.Body) 1428 1428 htmlDoc.AssertElement(t, fmt.Sprintf(`tr[data-entryname="repo1"] a[href="%s"]`, u.JoinPath("/user2/repo1").String()), true) 1429 + 1430 + // Check that a link to the submodule returns a redirect and that the redirect link is correct. 1431 + req = NewRequest(t, "GET", "/"+repo.FullName()+"/src/branch/"+repo.DefaultBranch+"/repo1") 1432 + resp = MakeRequest(t, req, http.StatusSeeOther) 1433 + 1434 + assert.Equal(t, u.JoinPath("/user2/repo1").String(), resp.Header().Get("Location")) 1429 1435 }) 1430 1436 } 1431 1437