diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 6a5feb322a..366637e544 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -448,7 +448,8 @@ func PrepareCompareDiff( if (headCommitID == ci.MergeBase && !ci.DirectComparison()) || headCommitID == ci.BaseCommitID { - ctx.Data["IsNothingToCompare"] = true + ctx.Data["CommitCount"] = 0 + ctx.Data["DiffNotAvailable"] = true if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil { config := unit.PullRequestsConfig() @@ -495,7 +496,6 @@ func PrepareCompareDiff( ctx.ServerError("GetDiffShortStat", err) return false } - ctx.Data["IsNothingToCompare"] = diffShortStat.NumFiles == 0 ctx.Data["DiffShortStat"] = diffShortStat ctx.Data["Diff"] = diff ctx.Data["DiffBlobExcerptData"] = &gitdiff.DiffBlobExcerptData{ diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 8dd21dd480..9f0e68d387 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -174,8 +174,8 @@ {{if and .IsSigned .PageIsComparePull}} - {{$allowCreatePR := and ($.CompareInfo.BaseRef.IsBranch) ($.CompareInfo.HeadRef.IsBranch) (not $.CompareInfo.DirectComparison) (or $.AllowEmptyPr (not .IsNothingToCompare))}} - {{if .IsNothingToCompare}} + {{$allowCreatePR := and ($.CompareInfo.BaseRef.IsBranch) ($.CompareInfo.HeadRef.IsBranch) (not $.CompareInfo.DirectComparison) (or $.AllowEmptyPr (not .DiffNotAvailable))}} + {{if .DiffNotAvailable}}
{{if $allowCreatePR}} {{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}} @@ -215,18 +215,20 @@
{{end}} {{else}}{{/* not singed-in or not for pull-request */}} - {{if .IsNothingToCompare}} + {{if .DiffNotAvailable}}
{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}
{{end}} {{end}} - {{if not .IsNothingToCompare}} + {{if or .CommitCount (not .DiffNotAvailable)}}
{{if .CommitCount}} {{template "repo/commits_table" .}} {{end}} - {{template "repo/diff/box" .}} + {{if not .DiffNotAvailable}} + {{template "repo/diff/box" .}} + {{end}}
{{end}}