From a22e5f86c6b4f0c58ae98463cda45f6804dbe1ca Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Tue, 16 Dec 2025 00:45:00 +0100 Subject: [PATCH] fix: Allow SHA-256 in PR commit URLs (#10309) Closes #9129. I decided to try myself in contributing to Forgejo after having found this bug mentioned on Fedi. I have also added a basic test for this behaviour, but this means that this PR adds a SHA-256 repo to the fixture set, so it can be reused in other tests. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10309 Reviewed-by: Lucas Reviewed-by: 0ko <0ko@noreply.codeberg.org> Reviewed-by: Gusted Co-authored-by: Nikita Karamov Co-committed-by: Nikita Karamov --- models/fixtures/branch.yml | 22 +++++++++++++ models/fixtures/issue.yml | 16 +++++++++ models/fixtures/issue_index.yml | 3 ++ models/fixtures/pull_request.yml | 13 ++++++++ models/fixtures/repo_unit.yml | 31 ++++++++++++++++++ models/fixtures/repository.yml | 31 ++++++++++++++++++ models/fixtures/user.yml | 2 +- models/issues/issue_test.go | 2 +- models/repo/repo_list_test.go | 14 ++++---- modules/indexer/issues/indexer_test.go | 16 ++++----- routers/web/user/home_test.go | 2 +- routers/web/web.go | 6 ++-- .../user2/repo256.git/FETCH_HEAD | 1 + .../user2/repo256.git/HEAD | 1 + .../user2/repo256.git/config | 7 ++++ .../user2/repo256.git/description | 1 + .../user2/repo256.git/hooks/post-receive | 16 +++++++++ .../repo256.git/hooks/post-receive.d/gitea | 3 ++ .../user2/repo256.git/hooks/pre-receive | 16 +++++++++ .../repo256.git/hooks/pre-receive.d/gitea | 3 ++ .../user2/repo256.git/hooks/proc-receive | 3 ++ .../repo256.git/hooks/proc-receive.d/gitea | 0 .../user2/repo256.git/hooks/update | 15 +++++++++ .../user2/repo256.git/hooks/update.d/gitea | 3 ++ .../user2/repo256.git/info/exclude | 6 ++++ .../user2/repo256.git/info/refs | 2 ++ .../user2/repo256.git/logs/HEAD | 1 + .../user2/repo256.git/logs/refs/heads/branch2 | 1 + .../user2/repo256.git/logs/refs/heads/master | 1 + ...64021404490ee747ce58e98d27c046f2e46f5f2f55 | Bin 0 -> 182 bytes ...d18ca6ed671de104dbeb9e846bb2ada4f8c6ee9674 | Bin 0 -> 104 bytes ...e3b1e9a7dcda1185436fe141f7749120a303721813 | Bin 0 -> 15 bytes ...43b5c4a19450b30865ddbc52d8f403e2d42127c6a8 | Bin 0 -> 44 bytes ...1f7feea2383903e02bb4b7600d37eb2bb6e934daba | Bin 0 -> 144 bytes ...8bea1d22ffb0d9e2e89d11fe0650ae06691cdb2578 | Bin 0 -> 68 bytes .../info/commit-graphs/commit-graph-chain | 1 + ...c01e73da0717f8fec878cbc35d506f97f9f8.graph | Bin 0 -> 1292 bytes .../user2/repo256.git/objects/info/packs | 1 + .../user2/repo256.git/refs/heads/branch2 | 1 + .../user2/repo256.git/refs/heads/master | 1 + .../user2/repo256.git/refs/pull/1/head | 1 + tests/integration/api_issue_test.go | 8 ++--- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/api_repo_test.go | 6 ++-- tests/integration/issue_test.go | 6 ++-- tests/integration/pull_commit_test.go | 27 +++++++++++++++ 46 files changed, 260 insertions(+), 32 deletions(-) create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/FETCH_HEAD create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/HEAD create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/config create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/description create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive.d/gitea create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive.d/gitea create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive.d/gitea create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/update create mode 100755 tests/gitea-repositories-meta/user2/repo256.git/hooks/update.d/gitea create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/info/exclude create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/info/refs create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/logs/HEAD create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/branch2 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/master create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/00/4581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/1a/f661f4f50eee8d79d1e4d18ca6ed671de104dbeb9e846bb2ada4f8c6ee9674 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/57/158942c61b6479923c5a43b5c4a19450b30865ddbc52d8f403e2d42127c6a8 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/7b/299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/93/7d619de4c607efc046798bea1d22ffb0d9e2e89d11fe0650ae06691cdb2578 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/info/commit-graphs/commit-graph-chain create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/info/commit-graphs/graph-b89845831ab35606e6a2cdfb07ccc01e73da0717f8fec878cbc35d506f97f9f8.graph create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/objects/info/packs create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/refs/heads/branch2 create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/refs/heads/master create mode 100644 tests/gitea-repositories-meta/user2/repo256.git/refs/pull/1/head diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 2a9e3105e6..8853dd4834 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -69,3 +69,25 @@ is_deleted: false deleted_by_id: 0 deleted_unix: 0 + +- id: 17 + repo_id: 66 + name: 'master' + commit_id: '7b299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba' + commit_message: 'Initial commit' + commit_time: 1764879244 + pusher_id: 2 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- id: 18 + repo_id: 66 + name: 'branch2' + commit_id: '004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55' + commit_message: 'PR' + commit_time: 1764879438 + pusher_id: 2 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index adb407f9c0..2fa7945aa0 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -372,3 +372,19 @@ created_unix: 1707270422 updated_unix: 1707270422 is_locked: false + +- id: 24 + repo_id: 66 + index: 1 + poster_id: 2 + original_author_id: 0 + name: PR + content: '' + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 1764879458 + updated_unix: 1764879458 + is_locked: false diff --git a/models/fixtures/issue_index.yml b/models/fixtures/issue_index.yml index de6e955804..897be08178 100644 --- a/models/fixtures/issue_index.yml +++ b/models/fixtures/issue_index.yml @@ -25,3 +25,6 @@ - group_id: 51 max_index: 1 + +- group_id: 66 + max_index: 1 diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 79051ffb6c..1dfe1b9c2c 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -119,3 +119,16 @@ index: 1 head_repo_id: 61 base_repo_id: 61 + +- id: 12 + type: 0 # gitea pull request + status: 2 # mergeable + issue_id: 24 + index: 1 + head_repo_id: 66 + base_repo_id: 66 + head_branch: branch2 + base_branch: master + merge_base: 004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 + has_merged: false + diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 773f238645..00326c8048 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -802,3 +802,34 @@ type: 10 config: "{}" created_unix: 946684810 + +- + id: 116 + repo_id: 66 + type: 1 + config: "{}" + created_unix: 1764879302 + +- id: 117 + repo_id: 66 + type: 2 + config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true,\"EnableDependencies\":true}" + created_unix: 1764879302 + +- id: 118 + repo_id: 66 + type: 3 + config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" + created_unix: 1764879302 + +- id: 119 + repo_id: 66 + type: 4 + config: "{}" + created_unix: 1764879302 + +- id: 120 + repo_id: 66 + type: 5 + config: "{}" + created_unix: 1764879302 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index d3214f39f8..f2029232bb 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1684,3 +1684,34 @@ is_fsck_enabled: true close_issues_via_commit_in_any_branch: false topics: '[]' + +- + id: 66 + owner_id: 2 + owner_name: user2 + lower_name: repo256 + name: repo256 + default_branch: master + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: false + fork_id: 0 + is_template: false + template_id: 0 + size: 24586 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + created_unix: 1764879302 + updated_unix: 1764879302 + topics: '[]' + object_format_name: 'sha256' diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 9e9cb2c1a6..ae5fcbff1e 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -70,7 +70,7 @@ num_followers: 2 num_following: 1 num_stars: 2 - num_repos: 18 + num_repos: 19 num_teams: 0 num_members: 0 visibility: 0 diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index 21f483b391..2059c5013a 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -431,7 +431,7 @@ func TestCountIssues(t *testing.T) { require.NoError(t, unittest.PrepareTestDatabase()) count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{}) require.NoError(t, err) - assert.EqualValues(t, 22, count) + assert.EqualValues(t, 23, count) } func TestIssueLoadAttributes(t *testing.T) { diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index 89873c299b..085f660f15 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -142,12 +142,12 @@ func getTestCases() []struct { { name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: optional.Some(false)}, - count: 35, + count: 36, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: optional.Some(false)}, - count: 40, + count: 41, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", @@ -162,7 +162,7 @@ func getTestCases() []struct { { name: "AllPublic/PublicRepositoriesOfOrganization", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: optional.Some(false), Template: optional.Some(false)}, - count: 35, + count: 36, }, { name: "AllTemplates", @@ -172,7 +172,7 @@ func getTestCases() []struct { { name: "OwnerSlashRepoSearch", opts: &repo_model.SearchRepoOptions{Keyword: "user/repo2", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0}, - count: 2, + count: 3, }, { name: "OwnerSlashSearch", @@ -420,15 +420,15 @@ func TestSearchRepositoryIDsByCondition(t *testing.T) { }{ { user: nil, - repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 1059}, + repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 66, 1059}, }, { user: unittest.AssertExistsAndLoadBean(t, &user.User{ID: 4}), - repoIDs: []int64{1, 3, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 1001, 1059}, + repoIDs: []int64{1, 3, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 66, 1001, 1059}, }, { user: unittest.AssertExistsAndLoadBean(t, &user.User{ID: 5}), - repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 1001, 1059}, + repoIDs: []int64{1, 4, 8, 9, 10, 11, 12, 14, 17, 18, 21, 23, 25, 27, 29, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 46, 47, 48, 49, 50, 51, 53, 57, 58, 60, 61, 62, 66, 1001, 1059}, }, } diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index ad27511be1..527627e0fc 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -157,7 +157,7 @@ func searchIssueByID(t *testing.T) { { // NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1. opts: *ToSearchOptions(t.Context(), "", &issues.IssuesOptions{AssigneeID: -1}), - expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2}, + expectedIDs: []int64{24, 22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2}, }, { opts: SearchOptions{ @@ -222,7 +222,7 @@ func searchIssueIsPull(t *testing.T) { SearchOptions{ IsPull: optional.Some(true), }, - []int64{22, 21, 12, 11, 20, 19, 9, 8, 3, 2}, + []int64{24, 22, 21, 12, 11, 20, 19, 9, 8, 3, 2}, }, } for _, test := range tests { @@ -242,7 +242,7 @@ func searchIssueIsClosed(t *testing.T) { SearchOptions{ IsClosed: optional.Some(false), }, - []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1}, + []int64{24, 22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1}, }, { SearchOptions{ @@ -305,7 +305,7 @@ func searchIssueByLabelID(t *testing.T) { SearchOptions{ ExcludedLabelIDs: []int64{1}, }, - []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3}, + []int64{24, 22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3}, }, } for _, test := range tests { @@ -325,7 +325,7 @@ func searchIssueByTime(t *testing.T) { SearchOptions{ UpdatedAfterUnix: optional.Some(int64(0)), }, - []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1}, + []int64{24, 22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1}, }, } for _, test := range tests { @@ -345,7 +345,7 @@ func searchIssueWithOrder(t *testing.T) { SearchOptions{ SortBy: internal.SortByCreatedAsc, }, - []int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22}, + []int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22, 24}, }, } for _, test := range tests { @@ -400,8 +400,8 @@ func searchIssueWithPaginator(t *testing.T) { PageSize: 5, }, }, - []int64{22, 21, 17, 16, 15}, - 22, + []int64{24, 22, 21, 17, 16}, + 23, }, } for _, test := range tests { diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go index d9f99bed05..12fe2ade18 100644 --- a/routers/web/user/home_test.go +++ b/routers/web/user/home_test.go @@ -78,7 +78,7 @@ func TestPulls(t *testing.T) { Pulls(ctx) assert.Equal(t, http.StatusOK, ctx.Resp.Status()) - assert.Len(t, ctx.Data["Issues"], 5) + assert.Len(t, ctx.Data["Issues"], 6) } func TestMilestones(t *testing.T) { diff --git a/routers/web/web.go b/routers/web/web.go index 1fd3ecb37c..4e10dcc67b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1559,7 +1559,7 @@ func registerRoutes(m *web.Route) { m.Group("/commits", func() { m.Get("", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommits) m.Get("/list", context.RepoRef(), repo.GetPullCommits) - m.Group("/{sha:[a-f0-9]{4,40}}", func() { + m.Group("/{sha:[a-f0-9]{4,64}}", func() { m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForSingleCommit) m.Post("/reviews/submit", context.RepoMustNotBeArchived(), web.Bind(forms.SubmitReviewForm{}), repo.SubmitReview) }) @@ -1571,8 +1571,8 @@ func registerRoutes(m *web.Route) { m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest) m.Group("/files", func() { m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForAllCommitsOfPr) - m.Get("/{sha:[a-f0-9]{4,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesStartingFromCommit) - m.Get("/{shaFrom:[a-f0-9]{4,40}}..{shaTo:[a-f0-9]{4,40}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForRange) + m.Get("/{sha:[a-f0-9]{4,64}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesStartingFromCommit) + m.Get("/{shaFrom:[a-f0-9]{4,64}}..{shaTo:[a-f0-9]{4,64}}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFilesForRange) m.Group("/reviews", func() { m.Get("/new_comment", repo.RenderNewCodeCommentForm) m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment) diff --git a/tests/gitea-repositories-meta/user2/repo256.git/FETCH_HEAD b/tests/gitea-repositories-meta/user2/repo256.git/FETCH_HEAD new file mode 100644 index 0000000000..cd4807748e --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/FETCH_HEAD @@ -0,0 +1 @@ +004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 branch 'branch2' of file:///data/git/repositories/user2/repo256 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/HEAD b/tests/gitea-repositories-meta/user2/repo256.git/HEAD new file mode 100644 index 0000000000..cb089cd89a --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests/gitea-repositories-meta/user2/repo256.git/config b/tests/gitea-repositories-meta/user2/repo256.git/config new file mode 100644 index 0000000000..d16e4615df --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/config @@ -0,0 +1,7 @@ +[extensions] + objectformat = sha256 +[core] + repositoryformatversion = 1 + filemode = true + bare = true + ignorecase = true diff --git a/tests/gitea-repositories-meta/user2/repo256.git/description b/tests/gitea-repositories-meta/user2/repo256.git/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive b/tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive new file mode 100755 index 0000000000..80ae57095c --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +data=$(cat) +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)/..} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do + test -x "${hook}" && test -f "${hook}" || continue + echo "${data}" | "${hook}" + exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do + [ ${i} -eq 0 ] || exit ${i} +done diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive.d/gitea b/tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive.d/gitea new file mode 100755 index 0000000000..2a84d521f5 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/post-receive.d/gitea @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +/usr/local/bin/gitea hook --config=/data/gitea/conf/app.ini post-receive diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive b/tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive new file mode 100755 index 0000000000..80ae57095c --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +data=$(cat) +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)/..} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do + test -x "${hook}" && test -f "${hook}" || continue + echo "${data}" | "${hook}" + exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do + [ ${i} -eq 0 ] || exit ${i} +done diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive.d/gitea b/tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive.d/gitea new file mode 100755 index 0000000000..00db788f31 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/pre-receive.d/gitea @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +/usr/local/bin/gitea hook --config=/data/gitea/conf/app.ini pre-receive diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive b/tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive new file mode 100755 index 0000000000..19746273df --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +/usr/local/bin/gitea hook --config=/data/gitea/conf/app.ini proc-receive diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive.d/gitea b/tests/gitea-repositories-meta/user2/repo256.git/hooks/proc-receive.d/gitea new file mode 100755 index 0000000000..e69de29bb2 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/update b/tests/gitea-repositories-meta/user2/repo256.git/hooks/update new file mode 100755 index 0000000000..b3570b0004 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/update @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0/..)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do + test -x "${hook}" && test -f "${hook}" || continue + "${hook}" $1 $2 $3 + exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do + [ ${i} -eq 0 ] || exit ${i} +done diff --git a/tests/gitea-repositories-meta/user2/repo256.git/hooks/update.d/gitea b/tests/gitea-repositories-meta/user2/repo256.git/hooks/update.d/gitea new file mode 100755 index 0000000000..3f5829639a --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/hooks/update.d/gitea @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# AUTO GENERATED BY GITEA, DO NOT MODIFY +/usr/local/bin/gitea hook --config=/data/gitea/conf/app.ini update $1 $2 $3 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/info/exclude b/tests/gitea-repositories-meta/user2/repo256.git/info/exclude new file mode 100644 index 0000000000..a5196d1be8 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/tests/gitea-repositories-meta/user2/repo256.git/info/refs b/tests/gitea-repositories-meta/user2/repo256.git/info/refs new file mode 100644 index 0000000000..90a282c1dc --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/info/refs @@ -0,0 +1,2 @@ +004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 refs/heads/branch2 +7b299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba refs/heads/main diff --git a/tests/gitea-repositories-meta/user2/repo256.git/logs/HEAD b/tests/gitea-repositories-meta/user2/repo256.git/logs/HEAD new file mode 100644 index 0000000000..028c208c7d --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/logs/HEAD @@ -0,0 +1 @@ +0000000000000000000000000000000000000000000000000000000000000000 7b299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba Gitea 1764879318 +0000 push diff --git a/tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/branch2 b/tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/branch2 new file mode 100644 index 0000000000..6a0e9b490a --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/branch2 @@ -0,0 +1 @@ +0000000000000000000000000000000000000000000000000000000000000000 004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 Gitea 1764879445 +0000 push diff --git a/tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/master b/tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/master new file mode 100644 index 0000000000..028c208c7d --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000000000000000000000000000 7b299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba Gitea 1764879318 +0000 push diff --git a/tests/gitea-repositories-meta/user2/repo256.git/objects/00/4581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 b/tests/gitea-repositories-meta/user2/repo256.git/objects/00/4581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 new file mode 100644 index 0000000000000000000000000000000000000000..0a492e6ecc918947a88140c77f2ec7dcc33d01d4 GIT binary patch literal 182 zcmV;n07?IN0hNzIN(C_x1zqP9*$dK1db$%3aW9B?gYL--4xe#kh#$PYA8+8YplVU; zvG3cAdC|Lh0x{VTNrT5i0BYCP6S$|knxKoOjzruY-cVWGvvuQ9R{@$Rhc7$vIiq@R z&B$-kLS73o3XL>$0G3NFjS48cv#SvGqVO9DTH$VP!M^9mamLr}vQ3LGcG`Yizl&~bf=NrkI6E;Zg$A`0u@&cwgN@b(^l0ZI2yvXX*Y@c;k- literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/objects/1a/f661f4f50eee8d79d1e4d18ca6ed671de104dbeb9e846bb2ada4f8c6ee9674 b/tests/gitea-repositories-meta/user2/repo256.git/objects/1a/f661f4f50eee8d79d1e4d18ca6ed671de104dbeb9e846bb2ada4f8c6ee9674 new file mode 100644 index 0000000000000000000000000000000000000000..9ce44f741c81fb45ed4163aec7bf3a9555e7126e GIT binary patch literal 104 zcmV-u0GI!G0V^p=O;xZoU@$Z=Ff%bxFl2DI;`gzBvC^z@QTpSJFPGoBCD`hm|IqP! z$wY<4%taEyP=!IRjxN5gdbueK;i8>R$D~s#C)q?fZ#}YbO2B50)Vq6vZhT>WbVX79 K*a`r}#U^DzGBYy( literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 b/tests/gitea-repositories-meta/user2/repo256.git/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 new file mode 100644 index 0000000000000000000000000000000000000000..711223894375fe1186ac5bfffdc48fb1fa1e65cc GIT binary patch literal 15 Wcmb~UJZ$(w;e#*)_x0DLJB A7ytkO literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/objects/7b/299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba b/tests/gitea-repositories-meta/user2/repo256.git/objects/7b/299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba new file mode 100644 index 0000000000000000000000000000000000000000..5fde414f0fd5cd0814c132590b7a771427f0b067 GIT binary patch literal 144 zcmV;B0B`?z0hNwH3c@fD06pgwdlzIkrb!k=yo%r-(qx07#zI*O{$9}+c$wP_ljq)> z0&&>rA_BY*#S<5C*<+BJ(fPn}ltjhaT1PA_Rw5UoD(DAHA9|)-MmvOP(o=8q0@pS* yO>jv|>hlVRE~n|Gns!CjBT(=z2DZ+@775Yh?}p0XqB%dBwsePI!Mp*DGCtW2146<8 literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/objects/93/7d619de4c607efc046798bea1d22ffb0d9e2e89d11fe0650ae06691cdb2578 b/tests/gitea-repositories-meta/user2/repo256.git/objects/93/7d619de4c607efc046798bea1d22ffb0d9e2e89d11fe0650ae06691cdb2578 new file mode 100644 index 0000000000000000000000000000000000000000..338f7538502d8a699ed1499e9cbac29e2f9c94b8 GIT binary patch literal 68 zcmV-K0K5Nq0RcGx#{YD3Wn~~VIRG&*Fg7$aAW}s^L`_95ZDasf6^TN|8)SKsJX%Aw a#G#Z>vj}C~yi(Zo1LD*nC&s7E5Aa}QVqx(2ba7*V02d(J2f}1=advSGfwEiNT^x;|>?aT!M6$dA5{#pG#DoD8 zFs?`OXc!>UfNSIC-N~h{OlEE=Od>3ve9zs_MZD})Kj8N1Nq)S3Xtm}n?ia4y%`A`k z-@D$*i%%~0EPIv=8No7OJ* zaqQi+5>VMv03?8bBh&DW-{jiFxlfLHmhCk6z3b{KposjxAH>wrT}P yEmS>Ars3-zuudScV}@(9)aEd@XN%7MWX@lDo!7c4alGV^9KOl@nNU{ literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/objects/info/packs b/tests/gitea-repositories-meta/user2/repo256.git/objects/info/packs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/objects/info/packs @@ -0,0 +1 @@ + diff --git a/tests/gitea-repositories-meta/user2/repo256.git/refs/heads/branch2 b/tests/gitea-repositories-meta/user2/repo256.git/refs/heads/branch2 new file mode 100644 index 0000000000..3c0ab7edd7 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/refs/heads/branch2 @@ -0,0 +1 @@ +004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 diff --git a/tests/gitea-repositories-meta/user2/repo256.git/refs/heads/master b/tests/gitea-repositories-meta/user2/repo256.git/refs/heads/master new file mode 100644 index 0000000000..cc7f90051c --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/refs/heads/master @@ -0,0 +1 @@ +7b299a0be8450b8304e30f1f7feea2383903e02bb4b7600d37eb2bb6e934daba diff --git a/tests/gitea-repositories-meta/user2/repo256.git/refs/pull/1/head b/tests/gitea-repositories-meta/user2/repo256.git/refs/pull/1/head new file mode 100644 index 0000000000..3c0ab7edd7 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo256.git/refs/pull/1/head @@ -0,0 +1 @@ +004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55 diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index df04a3a15b..581282223d 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -491,7 +491,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(publicOnlyToken) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 15) // 15 public issues + assert.Len(t, apiIssues, 16) // 16 public issues since := "2000-01-01T00:50:01+00:00" // 946687801 before := time.Unix(999307200, 0).Format(time.RFC3339) @@ -517,7 +517,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Equal(t, "22", resp.Header().Get("X-Total-Count")) + assert.Equal(t, "23", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "10") @@ -525,7 +525,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Equal(t, "22", resp.Header().Get("X-Total-Count")) + assert.Equal(t, "23", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 10) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -554,7 +554,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 8) + assert.Len(t, apiIssues, 9) query = url.Values{"owner": {"org3"}} // organization link.RawQuery = query.Encode() diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index c4f2309aac..cafdc1a7cc 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -30,6 +30,6 @@ func TestNodeinfo(t *testing.T) { assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "forgejo", nodeinfo.Software.Name) assert.Equal(t, 29, nodeinfo.Usage.Users.Total) - assert.Equal(t, 22, nodeinfo.Usage.LocalPosts) + assert.Equal(t, 23, nodeinfo.Usage.LocalPosts) assert.Equal(t, 4, nodeinfo.Usage.LocalComments) } diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index 1c17d5e04f..ca939dfa7b 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -96,9 +96,9 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 37}, - user: {count: 37}, - user2: {count: 37}, + nil: {count: 38}, + user: {count: 38}, + user2: {count: 38}, }, }, { diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 205c290413..2e7428a1ac 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -899,7 +899,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Equal(t, "22", resp.Header().Get("X-Total-Count")) + assert.Equal(t, "23", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "5") @@ -907,7 +907,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Equal(t, "22", resp.Header().Get("X-Total-Count")) + assert.Equal(t, "23", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 5) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -936,7 +936,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 8) + assert.Len(t, apiIssues, 9) query = url.Values{"owner": {"org3"}} // organization link.RawQuery = query.Encode() diff --git a/tests/integration/pull_commit_test.go b/tests/integration/pull_commit_test.go index 562cbcb334..a7dae29179 100644 --- a/tests/integration/pull_commit_test.go +++ b/tests/integration/pull_commit_test.go @@ -62,6 +62,33 @@ func TestPullCommitLinks(t *testing.T) { assert.Equal(t, "/user2/repo1/pulls/3/commits/5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commitLinkHref) } +func TestPullCommitLinksSHA256(t *testing.T) { + if !git.SupportHashSha256 { + t.Skip("skipping because installed Git version doesn't support SHA256") + return + } + + defer tests.PrepareTestEnv(t)() + + req := NewRequest(t, "GET", "/user2/repo256/pulls/1/commits") + resp := MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + + commitSha := htmlDoc.Find(".commit-list td.sha a.sha.label").First() + commitShaHref, commitShaOk := commitSha.Attr("href") + assert.True(t, commitShaOk) + assert.Equal(t, "/user2/repo256/pulls/1/commits/004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55", commitShaHref) + + commitLink := htmlDoc.Find(".commit-list td.message a").First() + commitLinkHref, commitLinkOk := commitLink.Attr("href") + assert.True(t, commitLinkOk) + assert.Equal(t, "/user2/repo256/pulls/1/commits/004581b3bb63754502364664021404490ee747ce58e98d27c046f2e46f5f2f55", commitLinkHref) + + commitReq := NewRequest(t, "GET", commitShaHref) + MakeRequest(t, commitReq, http.StatusOK) +} + func TestPullCommitSignature(t *testing.T) { t.Cleanup(func() { // Cannot use t.Context(), it is in the done state.