diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl
index 59e87d10c03..96f7bb084e7 100644
--- a/templates/repo/commits_table.tmpl
+++ b/templates/repo/commits_table.tmpl
@@ -1,7 +1,7 @@
- {{$showDiffBox := and .CommitCount (not .IsNothingToCompare)}}
+ {{$showDiffBox := or .CommitCount .DiffShortStat.NumFiles}}
{{if and .IsSigned .PageIsComparePull}}
{{$allowCreatePR := and ($.CompareInfo.BaseRef.IsBranch) ($.CompareInfo.HeadRef.IsBranch) (not $.CompareInfo.DirectComparison) (or $.AllowEmptyPr (not .IsNothingToCompare))}}
{{if .IsNothingToCompare}}
@@ -211,7 +211,7 @@
{{end}}
{{else}}{{/* not signed-in or not for pull-request */}}
- {{if and (not .CommitCount) $.CompareInfo.CompareBase}}
+ {{if and (not $showDiffBox) $.CompareInfo.CompareBase}}
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
{{end}}
{{end}}
diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go
index 3bff6772535..8fd28dd3235 100644
--- a/tests/integration/compare_test.go
+++ b/tests/integration/compare_test.go
@@ -16,6 +16,7 @@ import (
"gitea.dev/modules/git"
"gitea.dev/modules/git/gitcmd"
"gitea.dev/modules/test"
+ "gitea.dev/modules/translation"
"gitea.dev/modules/util"
"gitea.dev/routers/common"
repo_service "gitea.dev/services/repository"
@@ -136,6 +137,15 @@ func TestCompareBranches(t *testing.T) {
diffChanges = []string{"test.txt"}
inspectCompare(t, htmlDoc, diffCount, diffChanges)
+
+ req = NewRequest(t, "GET", "/user2/repo20/compare/8babce967f21b9dfa6987f943b91093dac58a4f0..c8e31bc7688741a5287fcde4fbb8fc129ca07027")
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc = NewHTMLParser(t, resp.Body)
+
+ inspectCompare(t, htmlDoc, 3, []string{"link_hi", "test.csv", "test.txt"})
+ assert.NotContains(t, htmlDoc.doc.Text(), translation.NewLocale("en-US").TrString("repo.commits.nothing_to_compare"))
+ commitsHeader := strings.Join(strings.Fields(htmlDoc.doc.Find(".ui.top.attached.header .flex-text-block").First().Text()), " ")
+ assert.Equal(t, "0 "+translation.NewLocale("en-US").TrString("repo.commits.commits"), commitsHeader)
}
func TestCompareWithRefSuffix(t *testing.T) {