From 5083ea72fb636ab1cadc33d14831cbdf326b7c3b Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Thu, 25 Apr 2024 21:46:25 +0000 Subject: [PATCH] [v7.0/forgejo] fix(ui): /settings/lfs/find 500 error (#3451) When in the repository settings, visiting - `LFS` to `/{owner}/{repo}/settings/lfs` - `Find pointer files` to `/{owner}/{repo}/settings/lfs/pointers` - `Find commits` to `/{owner}/{repo}/settings/lfs/find?oid=...` failed with an error 500 because of an incorrect evaluation of the template. Regression introduced by https://codeberg.org/forgejo/forgejo/commit/cbf923e87bca0f50c2c01a60ccf544b63c365e98 A test is added to visit the page and guard against future regressions. Refs: https://codeberg.org/forgejo/forgejo/issues/3438 (cherry picked from commit 078229a5e458c850a9fff711b4ebb11c5ce61756) Also has a backport of https://codeberg.org/forgejo/forgejo/pulls/3465/files to ensure the test fails. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3451 Reviewed-by: oliverpool Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- templates/repo/settings/lfs_file_find.tmpl | 4 ++-- tests/integration/lfs_view_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/templates/repo/settings/lfs_file_find.tmpl b/templates/repo/settings/lfs_file_find.tmpl index 809a028b2c..54dbdb482b 100644 --- a/templates/repo/settings/lfs_file_find.tmpl +++ b/templates/repo/settings/lfs_file_find.tmpl @@ -23,9 +23,9 @@ {{svg "octicon-git-branch"}}{{.BranchName}} - {{if .ParentHashes}} + {{if .ParentIDs}} {{ctx.Locale.Tr "repo.diff.parent"}} - {{range .ParentHashes}} + {{range .ParentIDs}} {{ShortSha .String}} {{end}} {{end}} diff --git a/tests/integration/lfs_view_test.go b/tests/integration/lfs_view_test.go index 1775fa629f..9dfcb3e698 100644 --- a/tests/integration/lfs_view_test.go +++ b/tests/integration/lfs_view_test.go @@ -80,4 +80,26 @@ func TestLFSRender(t *testing.T) { content := doc.Find("div.file-view").Text() assert.Contains(t, content, "Testing READMEs in LFS") }) + + t.Run("/settings/lfs/pointers", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + // visit /user2/lfs/settings/lfs/pointer + req := NewRequest(t, "GET", "/user2/lfs/settings/lfs/pointers") + resp := session.MakeRequest(t, req, http.StatusOK) + + // follow the first link to /user2/lfs/settings/lfs/find?oid=.... + filesTable := NewHTMLParser(t, resp.Body).doc.Find("#lfs-files-table") + assert.Contains(t, filesTable.Text(), "Find commits") + lfsFind := filesTable.Find(`.primary.button[href^="/user2"]`) + assert.Greater(t, lfsFind.Length(), 0) + lfsFindPath, exists := lfsFind.First().Attr("href") + assert.True(t, exists) + + assert.Contains(t, lfsFindPath, "oid=") + req = NewRequest(t, "GET", lfsFindPath) + resp = session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body).doc + assert.Equal(t, 1, doc.Find(`.sha.label[href="/user2/lfs/commit/73cf03db6ece34e12bf91e8853dc58f678f2f82d"]`).Length(), "could not find link to commit") + }) }