Skip to content

fix(compare): show the diff when a comparison has no commits - #39247

Open
4RH1T3CT0R7 wants to merge 2 commits into
go-gitea:mainfrom
4RH1T3CT0R7:fix-compare-dropped-commit
Open

fix(compare): show the diff when a comparison has no commits#39247
4RH1T3CT0R7 wants to merge 2 commits into
go-gitea:mainfrom
4RH1T3CT0R7:fix-compare-dropped-commit

Conversation

@4RH1T3CT0R7

Copy link
Copy Markdown
Contributor

The compare page only rendered the diff box when the comparison had at least one commit, and otherwise printed "There are no differences to show." A direct comparison whose head is an ancestor of its base hits that case: base..head lists no commits, yet the diff is not empty. This is where the Compare link on a force-push comment leads after the push dropped commits, so the link opened an empty page.

The diff box is now shown whenever there are commits or a non-empty diff, and the "no differences" message only appears when there is neither. The commits table header, which was hidden together with the diff box before, reads "0 Commits" in that case. An integration test on the repo20 fixture covers it.

Fixes #36390

The compare page only rendered the diff box when there was at least one
commit. A direct comparison whose head is an ancestor of its base, which
is where the Compare link of a force-push comment leads after commits
were dropped, has no commits but a non-empty diff, so the page showed
"There are no differences to show." instead of the diff.

Show the diff box whenever there are commits or a diff, keep the "no
differences" message for when there is neither, and let the commits
header read "0 Commits" in that case.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 5, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T07:26:57.524635Z 7c25968 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@4RH1T3CT0R7

Copy link
Copy Markdown
Contributor Author

Assisted-by: Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c25968d80

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/integration/compare_test.go Outdated
Comment on lines +142 to +144
// Direct compare of two commits where the head (add-csv) is an ancestor of the base (remove-files-b).
// This is what the "Compare" link of a force-push comment points to after the push has dropped
// commits: "base..head" lists no commits, but the diff is not empty and must still be shown.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace the narrative test comment

This three-line block narrates the scenario and the change rather than providing only a short, why-focused note; remove it or reduce it to a terse rationale to comply with the repository's explicit comment policy.

AGENTS.md reference: AGENTS.md:L10-L10

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Trimmed to one line in 6658822.

Comment thread tests/integration/compare_test.go Outdated

// 'link_hi' and 'test.csv' are restored, 'test.txt' is deleted
inspectCompare(t, htmlDoc, 3, []string{"link_hi", "test.csv", "test.txt"})
assert.NotContains(t, resp.Body.String(), translation.NewLocale("en-US").TrString("repo.commits.nothing_to_compare"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Assert against the parsed document or saved response

After NewHTMLParser(t, resp.Body) reads the response recorder's bytes.Buffer through EOF, resp.Body.String() contains only the unread remainder and is empty. Consequently this assertion passes even if the page still renders the nothing_to_compare message, so inspect htmlDoc or save the response string before parsing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, the parser had already drained the recorder. 6658822 asserts against the parsed document's text instead; with the template fix reverted this assertion now fails with the "no differences" message in the output, so it is no longer vacuous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compare Button in PR Timeline Shows Empty Result When Dropping a Commit

2 participants