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>
This commit is contained in:
Gnarwhal 2025-04-03 15:32:55 +00:00 committed by Gusted
parent 77b0275572
commit d28a64e538
2 changed files with 15 additions and 1 deletions

View file

@ -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"))
})
}