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 @@
- {{if .Commits}} - {{if gt .CommitCount 0}}{{.CommitCount}}{{end}}{{/* CommitCount is -1 when "follow rename" */}} + {{if or .Commits .IsDiffCompare}} + {{if ge .CommitCount 0}}{{.CommitCount}}{{end}}{{/* CommitCount is -1 when "follow rename" */}} {{ctx.Locale.Tr "repo.commits.commits"}} {{else if .IsNothingToCompare}} {{ctx.Locale.Tr "repo.commits.nothing_to_compare"}} diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 482c8a43460..dd4bcd4e274 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -168,7 +168,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) {