Skip to content

fix(pull): handle empty pull request files view to allow reviews#37783

Merged
wxiaoguang merged 5 commits into
go-gitea:mainfrom
eliroca:fix-empty-pr-review
May 19, 2026
Merged

fix(pull): handle empty pull request files view to allow reviews#37783
wxiaoguang merged 5 commits into
go-gitea:mainfrom
eliroca:fix-empty-pr-review

Conversation

@eliroca
Copy link
Copy Markdown
Contributor

@eliroca eliroca commented May 19, 2026

Example: https://gitea.com/eliroca/empty-pull-request/pulls/1

And the "Files Changed" tab: https://gitea.com/eliroca/empty-pull-request/pulls/1/files

after commit not found in PR commits

Instead, let's handle empty pull requests and show the usual UI.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 19, 2026
@eliroca eliroca changed the title Fix empty pull request files view to allow reviews fix(pull): handle empty pull request files view to allow reviews May 19, 2026
@eliroca eliroca force-pushed the fix-empty-pr-review branch from b84ddc6 to 774fbd5 Compare May 19, 2026 14:57
@bircni
Copy link
Copy Markdown
Member

bircni commented May 19, 2026

Why should we handle empty pull requests?
there is nothing to review we should the just show a better error

@wxiaoguang
Copy link
Copy Markdown
Contributor

Thank you for the fix, will do some fine tunes.

@eliroca
Copy link
Copy Markdown
Contributor Author

eliroca commented May 19, 2026

Why should we handle empty pull requests? there is nothing to review we should the just show a better error

A use-case is to use an empty PR as placeholder to trigger early reviews for a new branch.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 19, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 19, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented May 19, 2026

Made some changes:

  1. clarify the "commits list" range (added some comments)
  2. use 404 page instead of plain HTTP error
  3. make "beforeCommit" use the same logic as "afterCommit" (less "if", easier to read)
  4. merge the tests (save CI time)
  5. make test code explicitly assert the expected string, otherwise assert.Equal(t, 0 and assert.False( can succeed on almost every page.

@bircni bircni added reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels May 19, 2026
@wxiaoguang wxiaoguang requested a review from Copilot May 19, 2026 16:09
@eliroca
Copy link
Copy Markdown
Contributor Author

eliroca commented May 19, 2026

A PR also becomes empty after the changes get manually merged, outside of the PR.

@wxiaoguang
Copy link
Copy Markdown
Contributor

A PR also becomes empty after the changes get manually merged, outside of the PR.

I can see 2 different cases:

  1. the "head" and "base" commits are the same one, then no "commit list"
  2. the "head" and "base" are different, there are commits between them, but the diff is empty

And IIRC there are also some bugs reports for these edge cases, so maybe it needs more refactoring work in the future.

(yes, not in this PR's scope 😄 )

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the “Files Changed” view for empty pull requests (where the compare commit list can be empty because merge-base == head), so the page renders normally instead of erroring out, enabling users to submit PR reviews even when there are no file changes.

Changes:

  • Adjusts viewPullFiles commit resolution to gracefully handle empty PRs by falling back to loading HeadCommitID / CompareBase directly from the git repo when they are not present in the PR commit list.
  • Replaces the previous “commit not found in PR commits” 400 behavior with a NotFound response for invalid commit selections.
  • Adds an integration test asserting that the PR “Files” tab renders and shows the “Diff Content Not Available” placeholder for an empty PR.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
routers/web/repo/pull.go Makes the pull files view resilient to empty PR commit lists by fetching missing base/head commits from the repo.
tests/integration/pull_status_test.go Adds coverage to ensure empty PRs can load the /files tab and display the expected placeholder content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread routers/web/repo/pull.go
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented May 19, 2026

@eliroca does the new change look good to you?

ps: do you need the changes to be backported to 1.26? If yes, it needs to manually backport because the the main branch code changed a lot after PRs like Refactor pull request view (1) (#37380), so simple cherry-pick doesn't work.


Update: thanks to bircni , backport here: #37785

@wxiaoguang wxiaoguang added backport/done All backports for this PR have been created backport/manual No power to the bots! Create your backport yourself! backport/v1.26 This PR should be backported to Gitea 1.26 labels May 19, 2026
bircni added a commit that referenced this pull request May 19, 2026
)

Backport #37783. Manually adapted for the pre-refactor
pull view code (preparePullViewPullInfo / MergeBase).
@eliroca
Copy link
Copy Markdown
Contributor Author

eliroca commented May 19, 2026

@wxiaoguang: with this change, on repos with unrelated git histories, looking at the PR throws:

500 Internal Server Error
An error occurred:

GetCompareInfo, MergeBase: get merge-base of 7f5ea225bc4ee889b16bc5f7b4df104f6fa86b573952e58d3aaa8ded73770317 and 255e20faae919f1559f9c831d073036810dc7c7aec38c98ff0efea0240430837 failed: exit status 1 - 

I specifically tested that, as I've split the changes in this PR from a commit tackling both: empty PRs and unrelated histories diff: eliroca@a12e6e0

Example PR with unrelated histories, no diff is shown: https://gitea.com/eliroca/freetype2/pulls/1

logs here
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:gitcmd.(*Command).StartWithStderr, repo:.../eroca/freetype2.git): /usr/bin/git cat-file --batch-command
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:git.(*Repository).hashObjectBytes, repo:.../eroca/freetype2.git): /usr/bin/git hash-object --stdin
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:repo.GetMergedBaseCommitID, repo:.../eroca/freetype2.git): /usr/bin/git rev-list -1 --skip=1 255e20faae919f1559f9c831d073036810dc7c7aec38c98ff0efea0240430837
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:gitrepo.GetDiffShortStatByCmdArgs, repo:.../eroca/freetype2.git): /usr/bin/git diff --shortstat 381934cb51593257d5a27e88fd85438aa9c75b255c1d21d0fdc9441a4e462430 255e20faae919f1559f9c831d073036810dc7c7aec38c98ff0efea0240430837
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 services/pull/pull.go:815:GetSquashMergeCommitMessages() [E] Unable to get merge base commit:  Error: object does not exist [id: , rel_path: ]
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:git.GetFullCommitID, repo:.../eroca/freetype2.git): /usr/bin/git rev-parse refs/heads/slfo-1.2
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:git.GetFullCommitID, repo:.../eroca/freetype2.git): /usr/bin/git rev-parse refs/pull/3/head
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../git/gitcmd/command.go:422:(*Command).Start() [D] git.Command: git.Run(by:gitrepo.MergeBase, repo:.../eroca/freetype2.git): /usr/bin/git merge-base -- 7f5ea225bc4ee889b16bc5f7b4df104f6fa86b573952e58d3aaa8ded73770317 255e20faae919f1559f9c831d073036810dc7c7aec38c98ff0efea0240430837
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 routers/web/repo/pull.go:595:prepareViewPullInfo() [E] GetCompareInfo: MergeBase: get merge-base of 7f5ea225bc4ee889b16bc5f7b4df104f6fa86b573952e58d3aaa8ded73770317 and 255e20faae919f1559f9c831d073036810dc7c7aec38c98ff0efea0240430837 failed: exit status 1 -
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 .../context/context_response.go:82:(*Context).HTML() [D] Template: status/500
Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 HTTPRequest [I] router: completed GET /eroca/freetype2/pulls/3 for <IP>:55428, 500 Internal Server Error in 100.4ms @ repo/issue_view.go:317(repo.ViewIssue)

@wxiaoguang
Copy link
Copy Markdown
Contributor

@wxiaoguang: with this change, on repos with unrelated git histories, looking at the PR throws:

IIRC the "unrelated git histories" problems should have been fixed by Fix compare dropdown for branches without common history (#37470)

Is there a change in this PR related to "unrelated git histories"?

@wxiaoguang
Copy link
Copy Markdown
Contributor

Mai 19 19:25:05 gitea.local gitea[10554]: 2026/05/19 19:25:05 routers/web/repo/pull.go:595:prepareViewPullInfo() [E] GetCompareInfo: MergeBase: get merge-base of 7f5ea225bc4ee889b16bc5f7b4df104f6fa86b573952e58d3aaa8ded73770317 and 255e20faae919f1559f9c831d073036810dc7c7aec38c98ff0efea0240430837 failed: exit status 1 -

And there is no "routers/web/repo/pull.go:595:prepareViewPullInfo() " on main branch

@eliroca
Copy link
Copy Markdown
Contributor Author

eliroca commented May 19, 2026

I was testing with 1.26.1, sorry for the noise if this is meanwhile fixed in main.

@wxiaoguang
Copy link
Copy Markdown
Contributor

I was testing with 1.26.1, sorry for the noise if this is meanwhile fixed in main.

1.26 branch also has the fix : #37472. (also thanks to @bircni)

@bircni
Copy link
Copy Markdown
Member

bircni commented May 19, 2026

So merge?

@eliroca
Copy link
Copy Markdown
Contributor Author

eliroca commented May 19, 2026

Can you please verify that the changes don't break PRs with unrelated histories as in my test?

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented May 19, 2026

Can you please verify that the changes don't break PRs with unrelated histories as in my test?

Not quite sure about what you are referring to.

The changes made by me:

  • 8dd0517 : it is the same logic as yours (refactor the test to a more stable approach)
  • 7350a67 : merge the tests (your test logic is still kept)
  • e500b56 : it only added a comment FIXME

If you'd like to improve, feel free to make more improvements and/or add more tests.

@eliroca
Copy link
Copy Markdown
Contributor Author

eliroca commented May 19, 2026

It is not related to the changes here, my assumption was wrong. Please proceed here, I'll continue with a test for unrelated histories PRs tomorrow, and will follow up with a PR possibly. Sorry again for the noise.

@wxiaoguang wxiaoguang merged commit 9c8d55d into go-gitea:main May 19, 2026
25 checks passed
@GiteaBot GiteaBot added this to the 1.27.0 milestone May 19, 2026
wxiaoguang added a commit that referenced this pull request May 19, 2026
) (#37785)

Backport #37783

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
silverwind added a commit to silverwind/gitea that referenced this pull request May 19, 2026
* origin/main: (104 commits)
  fix(deps): update module github.com/go-git/go-git/v5 to v5.19.1 [security] (go-gitea#37786)
  fix(pull): handle empty pull request files view to allow reviews (go-gitea#37783)
  fix(markup): make RenderString never fail (go-gitea#37779)
  fix(markup): wrap indented code blocks for the code-copy button (go-gitea#37748)
  fix(permissions): Fix reading permission (go-gitea#37769)
  fix: add natural sort to sortTreeViewNodes (go-gitea#37772)
  fix: package creation unique conflict (go-gitea#37774)
  fix(deps): update npm dependencies (go-gitea#37768)
  fix(deps): update module gitlab.com/gitlab-org/api/client-go/v2 to v2.26.0 (go-gitea#37771)
  ci: split giteabot workflow (go-gitea#37770)
  [skip ci] Updated translations via Crowdin
  fix: Unify public-only token filtering in API queries and repo access checks (go-gitea#37118)
  fix(deps): update module google.golang.org/grpc to v1.81.1 (go-gitea#37762)
  chore: make DefaultTitleSource default to auto to match GitHub (go-gitea#37767)
  ci: fix cache-related issues (go-gitea#37761)
  chore: fix tests (go-gitea#37760)
  refactor(waitgroup): replace Add/Done goroutines with WaitGroup.Go (go-gitea#37764)
  fix(deps): update go dependencies (go-gitea#37752)
  chore(deps): update action dependencies (go-gitea#37751)
  fix(deps): update module github.com/google/go-github/v85 to v86 (go-gitea#37754)
  ...

# Conflicts:
#	.github/workflows/pull-db-tests.yml
#	modules/storage/s3_test.go
eleboucher pushed a commit to eleboucher/apoci that referenced this pull request May 20, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [code.gitea.io/gitea](https://github.com/go-gitea/gitea) | `v1.26.1` → `v1.26.2` | ![age](https://developer.mend.io/api/mc/badges/age/go/code.gitea.io%2fgitea/v1.26.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/code.gitea.io%2fgitea/v1.26.1/v1.26.2?slim=true) |

---

### Release Notes

<details>
<summary>go-gitea/gitea (code.gitea.io/gitea)</summary>

### [`v1.26.2`](https://github.com/go-gitea/gitea/releases/tag/v1.26.2)

[Compare Source](go-gitea/gitea@v1.26.1...v1.26.2)

- SECURITY
  - fix(permissions): Fix reading permission ([#&#8203;37769](go-gitea/gitea#37769))
  - fix(actions): make artifact signature payloads unambiguous ([#&#8203;37707](go-gitea/gitea#37707))
  - fix: Unify public-only token filtering in API queries and repo access checks ([#&#8203;37118](go-gitea/gitea#37118))
  - fix: Add missed token scope checking ([#&#8203;37735](go-gitea/gitea#37735))
  - fix(oauth): bind token exchanges to the original client request ([#&#8203;37704](go-gitea/gitea#37704))
  - fix(oauth): strengthen PKCE validation and refresh token replay protection ([#&#8203;37706](go-gitea/gitea#37706))
  - fix(web): enforce token scopes on raw, media, and attachment downloads ([#&#8203;37698](go-gitea/gitea#37698))
  - fix(security): enforce wiki git writes and LFS token access at request time ([#&#8203;37695](go-gitea/gitea#37695))
  - feat(api): encrypt AWS creds ([#&#8203;37679](go-gitea/gitea#37679))
  - fix(deps): update dependency mermaid to v11.15.0 \[security], add e2e test
  - fix(packages): Add label for private and internal package and fix composor package source permission check ([#&#8203;37610](go-gitea/gitea#37610))
  - fix(git): Fix smart http request scope bug ([#&#8203;37583](go-gitea/gitea#37583))
  - Fix basic auth bug ([#&#8203;37503](go-gitea/gitea#37503))
  - Fix allow maintainer edit permission check ([#&#8203;37479](go-gitea/gitea#37479)) ([#&#8203;37484](go-gitea/gitea#37484))
  - Fix URL sanitization to handle schemeless credentials ([#&#8203;37440](go-gitea/gitea#37440)) ([#&#8203;37471](go-gitea/gitea#37471))
  - Fix attachment Content-Security-Policy ([#&#8203;37455](go-gitea/gitea#37455)) ([#&#8203;37464](go-gitea/gitea#37464))
  - chore(deps): bump go-git/go-git/v5 to 5.19.0 ([#&#8203;37608](go-gitea/gitea#37608))

- BUGFIXES
  - fix(pull): handle empty pull request files view to allow reviews ([#&#8203;37783](go-gitea/gitea#37783))
  - fix(markup): make RenderString never fail ([#&#8203;37779](go-gitea/gitea#37779))
  - fix: add natural sort to sortTreeViewNodes ([#&#8203;37772](go-gitea/gitea#37772))
  - fix: package creation unique conflict ([#&#8203;37774](go-gitea/gitea#37774))
  - fix!: add DEFAULT\_TITLE\_SOURCE setting for pull request title default behavior ([#&#8203;37465](go-gitea/gitea#37465))
  - fix: Allow direct commits for unprotected files with push restrictions ([#&#8203;37657](go-gitea/gitea#37657))
  - fix(actions): wrong assumption that run id always >= job id ([#&#8203;37737](go-gitea/gitea#37737))
  - fix(auth): set User-Agent on avatar fetch and sync avatar on link-account register ([#&#8203;37564](go-gitea/gitea#37564)) ([#&#8203;37588](go-gitea/gitea#37588))
  - fix(actions): deadlock between PrepareRunAndInsert and UpdateTaskByState ([#&#8203;37692](go-gitea/gitea#37692))
  - fix(repo): /generate must sync the branch table for the new repo ([#&#8203;37693](go-gitea/gitea#37693))
  - build: Fix snap build (1.26)
  - fix(actions): run TransferLogs on UpdateLog{Rows:\[], NoMore:true} ([#&#8203;37631](go-gitea/gitea#37631))
  - fix show correct mergebase
  - fix: make clone URL respect public URL detection setting ([#&#8203;37615](go-gitea/gitea#37615))
  - fix: "run as root" check ([#&#8203;37622](go-gitea/gitea#37622))
  - chore(deps): update dependency go to v1.26.3 ([#&#8203;37601](go-gitea/gitea#37601))
  - Compare dropdown fails when selecting branch with no common merge-base ([#&#8203;37470](go-gitea/gitea#37470))
  - fix: treat email addresses case-insensitively ([#&#8203;37600](go-gitea/gitea#37600))
  - fix(actions): fix blank lines after ::endgroup:: ([#&#8203;37597](go-gitea/gitea#37597))
  - fix(actions): report individual step status in workflow job API response ([#&#8203;37592](go-gitea/gitea#37592))
  - fix: Invalid UTF-8 commit messages in JSON API responses ([#&#8203;37542](go-gitea/gitea#37542))
  - fix: use consistent GetUser family functions ([#&#8203;37553](go-gitea/gitea#37553))
  - fix(api): return 409 message instead of empty JSON for wrong commit id ([#&#8203;37572](go-gitea/gitea#37572))
  - fix(actions): prevent panic when workflow contains null jobs ([#&#8203;37570](go-gitea/gitea#37570))
  - Make ServeSetHeaders default to download attachment if filename exists ([#&#8203;37552](go-gitea/gitea#37552)) ([#&#8203;37555](go-gitea/gitea#37555))
  - Fix(actions): validate workflow param to prevent 500 error ([#&#8203;37546](go-gitea/gitea#37546)) ([#&#8203;37554](go-gitea/gitea#37554))
  - Don't unblock run-level-concurrency-blocked runs in the resolver ([#&#8203;37461](go-gitea/gitea#37461)) ([#&#8203;37538](go-gitea/gitea#37538))
  - Fix(packages): use file names for generic web downloads ([#&#8203;37514](go-gitea/gitea#37514)) ([#&#8203;37520](go-gitea/gitea#37520))
  - Fix merge autodetect can't close other PRs but only the last one when multiple PRs are pushed at once ([#&#8203;37512](go-gitea/gitea#37512)) ([#&#8203;37516](go-gitea/gitea#37516))
  - Fix update branch protection order ([#&#8203;37508](go-gitea/gitea#37508)) ([#&#8203;37513](go-gitea/gitea#37513))
  - Fix mCaptcha broken after Vite migration ([#&#8203;37492](go-gitea/gitea#37492)) ([#&#8203;37509](go-gitea/gitea#37509))
  - Fix review submission from single-commit PR view ([#&#8203;37475](go-gitea/gitea#37475)) ([#&#8203;37485](go-gitea/gitea#37485))
  - Fix scheduled action panic with null event payload ([#&#8203;37459](go-gitea/gitea#37459)) ([#&#8203;37466](go-gitea/gitea#37466))
  - Make GetPossibleUserByID can handle deleted user ([#&#8203;37430](go-gitea/gitea#37430)) ([#&#8203;37431](go-gitea/gitea#37431))
  - Remove excessive quote from terraform instructions ([#&#8203;37424](go-gitea/gitea#37424)) ([#&#8203;37426](go-gitea/gitea#37426))
  - Fix color regressions, add `priority` color ([#&#8203;37417](go-gitea/gitea#37417)) ([#&#8203;37421](go-gitea/gitea#37421))

- MISC
  - Add CurrentURL template variable back ([#&#8203;37444](go-gitea/gitea#37444)) ([#&#8203;37449](go-gitea/gitea#37449))

Instances on **[Gitea Cloud](https://cloud.gitea.com)** will be automatically upgraded to this version during the specified maintenance window.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.erwanleboucher.dev/eleboucher/apoci/pulls/47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/manual No power to the bots! Create your backport yourself! backport/v1.26 This PR should be backported to Gitea 1.26 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants