Skip to content

Commit

Permalink
fix compare link in active feeds for new branch
Browse files Browse the repository at this point in the history
fix go-gitea#19144

Signed-off-by: a1012112796 <1012112796@qq.com>
  • Loading branch information
a1012112796 committed Mar 20, 2022
1 parent 83a2f79 commit 622a594
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion services/repository/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,25 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
if len(commits.Commits) > setting.UI.FeedMaxCommitNum {
commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum]
}
commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)

oldCommitID := opts.OldCommitID
if oldCommitID == git.EmptySHA && len(commits.Commits) > 0 {
oldCommitID = commits.Commits[len(commits.Commits)-1].Sha1
oldCommit, err := gitRepo.GetCommit(oldCommitID)
if err != nil {
log.Error("gitRepo.GetCommit %s/%s failed: %v", repo.ID, oldCommitID, err)
}

for i := 0; i < oldCommit.ParentCount(); i++ {
commitID, _ := oldCommit.ParentID(i)
if !commitID.IsZero() {
oldCommitID = commitID.String()
break
}
}
}

commits.CompareURL = repo.ComposeCompareURL(oldCommitID, opts.NewCommitID)
notification.NotifyPushCommits(pusher, repo, opts, commits)

if err = models.RemoveDeletedBranchByName(repo.ID, branch); err != nil {
Expand Down

0 comments on commit 622a594

Please sign in to comment.