Fix compare dropdown for branches without common history#37470
Fix compare dropdown for branches without common history#37470bircni merged 13 commits intogo-gitea:mainfrom
Conversation
…sons - Introduced `ErrNoMergeBase` type to handle cases where two branches do not share a common merge base. - Updated `MergeBase` function to return this error type when applicable. - Enhanced the compare functionality to display a warning message in the UI when no common merge base is found. - Added tests to verify behavior when comparing branches with no common history. - Updated locale file to include a message for the no common history scenario.
Co-Authored-By: Codex <codex@openai.com>
|
Took a deep look, I found that the legacy code is not quite right. For example: after GetHeadOwnerAndRepo gets introduced, Will take a deeper look and maybe fix the legacy problems together. |
Thank you !!! |
|
Much more changes than I thought (more problems in legacy code than it looks ....). I think it's worth to do the deep clean up changes. So I guess no need to backport it (the problem has been there for many years, and it doesn't really block daily work, just bad user experience). |
There was a problem hiding this comment.
Pull request overview
Fixes compare UI/server handling when base and head refs have no common merge base (unrelated histories), avoiding 500s and keeping branch selectors usable with a clear warning.
Changes:
- Treat “no merge base” as a non-fatal condition during compare info generation and render a warning instead of erroring.
- Refactor compare info parsing and compare diff preparation, and wire flash alerts into the compare template.
- Add regression tests for merge-base “unrelated history” detection and compare page behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/compare_test.go | Adds integration coverage for compare selection with unrelated histories. |
| templates/repo/diff/compare.tmpl | Renders flash alerts on compare page (for the new warning). |
| services/git/compare.go | Updates compare info generation to tolerate missing merge base. |
| routers/web/repo/pull.go | Switches PR-creation handler to new compare parsing and error handling. |
| routers/web/repo/compare.go | Refactors compare parsing/diff prep and adds no-merge-base warning behavior. |
| options/locale/locale_en-US.json | Adds localized warning text for no common merge base. |
| modules/gitrepo/merge.go | Classifies merge-base “no common history” as not-exist. |
| modules/gitrepo/compare_test.go | Adds unit test for MergeBase with unrelated histories. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@wxiaoguang would really Like to backport as this bothered us very much today and will still do in the next few weeks/months |
|
OK, maybe you can use the early commits as backport. |
The permission-denied path in parseCompareInfo returns
util.NewNotExistErrorf("") so the empty message wouldn't leak why the
404 happened. CompareAndPullRequestPost was passing err.Error() into
ctx.JSONError, which surfaced an empty errorMessage to the client.
Route ErrNotExist through ctx.JSONErrorNotFound() so it sends a
generic localized 404 message regardless of the underlying error,
matching the GET path's ctx.NotFound(nil) behavior. ErrInvalidArgument
keeps its descriptive message via JSONError.
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
Small error-message fixup added in 109fef5. |
* main: Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior (go-gitea#37465) Fix compare dropdown for branches without common history (go-gitea#37470) FIX: URL sanitization to handle schemeless credentials (go-gitea#37440) Refactor pull request view (4) (go-gitea#37451) Fix scheduled action panic with null event payload (go-gitea#37459) Fix attachment Content-Security-Policy (go-gitea#37455) [skip ci] Updated translations via Crowdin Rename CurrentRefPath to CurrentRefSubURL (go-gitea#37453) Clean up org pages layout (go-gitea#37445) Fix script error alert (go-gitea#37458) Fix inconsistent disabled styling on logged-out repo header buttons (go-gitea#37406) Add API endpoint to reply to pull request review comments (go-gitea#36683) Add CurrentURL template variable back (go-gitea#37444)
|
-> Refactor compare diff/pull page (1) #37481 |
Summary
Fixes #37469