mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-20 05:59:22 +00:00
[v11.0/forgejo] fix: handle viewing a submodule entry (#7450)
Some checks failed
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
/ release (push) Has been cancelled
Some checks failed
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
/ release (push) Has been cancelled
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/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 Co-authored-by: Gnarwhal <git.aspect893@passmail.net> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7450 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
52da8aab7e
commit
7bc4f4976e
2 changed files with 15 additions and 1 deletions
|
@ -1044,7 +1044,15 @@ func renderHomeCode(ctx *context.Context) {
|
||||||
return
|
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)
|
renderDirectory(ctx)
|
||||||
} else {
|
} else {
|
||||||
renderFile(ctx, entry)
|
renderFile(ctx, entry)
|
||||||
|
|
|
@ -1423,6 +1423,12 @@ func TestRepoSubmoduleView(t *testing.T) {
|
||||||
|
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
htmlDoc.AssertElement(t, fmt.Sprintf(`tr[data-entryname="repo1"] a[href="%s"]`, u.JoinPath("/user2/repo1").String()), true)
|
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