Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ 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{
Expand Down Expand Up @@ -532,24 +533,26 @@ func PrepareCompareDiff(
return false
}

commits, err := processGitCommits(ctx, ci.Commits)
if err != nil {
ctx.ServerError("processGitCommits", err)
return false
}
ctx.Data["Commits"] = commits
ctx.Data["CommitCount"] = len(commits)

title := ci.HeadRef.ShortName()
if len(commits) == 1 {
c := commits[0]
title = strings.TrimSpace(c.UserCommit.Summary())

body := strings.Split(strings.TrimSpace(c.UserCommit.Message()), "\n")
if len(body) > 1 {
ctx.Data["content"] = strings.Join(body[1:], "\n")
if len(ci.Commits) > 0 {
commits, err := processGitCommits(ctx, ci.Commits)
if err != nil {
ctx.ServerError("processGitCommits", err)
return false
}
ctx.Data["Commits"] = commits
if len(commits) == 1 {
c := commits[0]
title = strings.TrimSpace(c.UserCommit.Summary())

body := strings.Split(strings.TrimSpace(c.UserCommit.Message()), "\n")
if len(body) > 1 {
ctx.Data["content"] = strings.Join(body[1:], "\n")
}
}
}
ctx.Data["CommitCount"] = len(ci.Commits)

if len(title) > 255 {
var trailer string
Expand Down
9 changes: 5 additions & 4 deletions templates/repo/diff/compare.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
</div>
</div>

{{$showDiffBox := and .CommitCount (not .IsNothingToCompare)}}
{{if and .IsSigned .PageIsComparePull}}
{{$allowCreatePR := and ($.CompareInfo.BaseRef.IsBranch) ($.CompareInfo.HeadRef.IsBranch) (not $.CompareInfo.DirectComparison) (or $.AllowEmptyPr (not .IsNothingToCompare))}}
{{if .IsNothingToCompare}}
Expand Down Expand Up @@ -216,15 +215,17 @@
</div>
{{end}}
{{else}}{{/* not singed-in or not for pull-request */}}
{{if not .CommitCount}}
{{if .IsNothingToCompare}}
<div class="ui segment">{{ctx.Locale.Tr "repo.commits.nothing_to_compare"}}</div>
{{end}}
{{end}}
</div>

{{if $showDiffBox}}
{{if not .IsNothingToCompare}}
<div class="ui container fluid padded tw-my-4">
{{template "repo/commits_table" .}}
{{if .CommitCount}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it right?

Copy link
Member Author

Choose a reason for hiding this comment

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

{{template "repo/commits_table" .}}
{{end}}
{{template "repo/diff/box" .}}
</div>
{{end}}
Expand Down