Skip to content

fix(api): handle fork-only commits in compare API (#37185)#37199

Merged
lunny merged 1 commit into
go-gitea:release/v1.26from
GiteaBot:backport-37185-v1.26
Apr 13, 2026
Merged

fix(api): handle fork-only commits in compare API (#37185)#37199
lunny merged 1 commit into
go-gitea:release/v1.26from
GiteaBot:backport-37185-v1.26

Conversation

@GiteaBot
Copy link
Copy Markdown
Collaborator

Backport #37185 by @Mohit25022005

Fix 500 error when comparing branches across fork repositories

Problem

The compare API returns a 500 Internal Server Error when comparing branches where the head commit exists only in the fork repository.

Cause

The API was using the base repository's GitRepo and repository context when converting commits. This fails when the commit does not exist in the base repository, resulting in a "fatal: bad object" error.

Solution

Use the head repository and HeadGitRepo when available to ensure commits are resolved in the correct repository context.

Result

  • Fixes "fatal: bad object" error
  • Enables proper comparison between base and fork repositories
  • Prevents 500 Internal Server Error

Fixes #37168

Fix 500 error when comparing branches across fork repositories

## Problem

The compare API returns a 500 Internal Server Error when comparing
branches where the head commit exists only in the fork repository.

## Cause

The API was using the base repository's GitRepo and repository context
when converting commits. This fails when the commit does not exist in
the base repository, resulting in a "fatal: bad object" error.

## Solution

Use the head repository and HeadGitRepo when available to ensure commits
are resolved in the correct repository context.

## Result

* Fixes "fatal: bad object" error
* Enables proper comparison between base and fork repositories
* Prevents 500 Internal Server Error

Fixes go-gitea#37168

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@GiteaBot GiteaBot requested review from bircni and lunny April 13, 2026 17:26
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 13, 2026
@GiteaBot GiteaBot added this to the 1.26.0 milestone Apr 13, 2026
@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 Apr 13, 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 Apr 13, 2026
@lunny lunny enabled auto-merge (squash) April 13, 2026 17:30
@lunny lunny merged commit 789a3d3 into go-gitea:release/v1.26 Apr 13, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants