aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2022-03-23 21:40:12 +0800
committerGitHub <noreply@github.com>2022-03-23 13:40:12 +0000
commit0eff23dae09f6127a39b53c8c3d82db2cd1ada38 (patch)
tree6b589dc070f28d951b5f74f338cd764182349526 /services/repository
parentd8f578412ebbf5b05de254a717f71cf5d3f5dab1 (diff)
downloadgitea-0eff23dae09f6127a39b53c8c3d82db2cd1ada38.tar.gz
gitea-0eff23dae09f6127a39b53c8c3d82db2cd1ada38.zip
Fix compare link in active feeds for new branch (#19149)
When a new branch is pushed the old SHA is always listed as the empty sha and thus the compare link that is created does not work correctly. Therefore when creating the compare link for new branches: 1. Attempt to get the parent of the first commit and use that as the basis for the compare link. 2. If this is not possible make a comparison to the default branch 3. Finally if that is not possible simply do not show a compare link. However, there are multiple broken compare links remaining therefore, in order for these to not break we will simply make the compare link redirect to the default branch. Fix #19144 Signed-off-by: a1012112796 <1012112796@qq.com> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/repository')
-rw-r--r--services/repository/push.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/services/repository/push.go b/services/repository/push.go
index 6cdfa1b4c2..8fbd5f5186 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -222,7 +222,34 @@ 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 {
+ oldCommit, err := gitRepo.GetCommit(commits.Commits[len(commits.Commits)-1].Sha1)
+ if err != nil && !git.IsErrNotExist(err) {
+ log.Error("unable to GetCommit %s from %-v: %v", oldCommitID, repo, err)
+ }
+ if oldCommit != nil {
+ for i := 0; i < oldCommit.ParentCount(); i++ {
+ commitID, _ := oldCommit.ParentID(i)
+ if !commitID.IsZero() {
+ oldCommitID = commitID.String()
+ break
+ }
+ }
+ }
+ }
+
+ if oldCommitID == git.EmptySHA && repo.DefaultBranch != branch {
+ oldCommitID = repo.DefaultBranch
+ }
+
+ if oldCommitID != git.EmptySHA {
+ commits.CompareURL = repo.ComposeCompareURL(oldCommitID, opts.NewCommitID)
+ } else {
+ commits.CompareURL = ""
+ }
+
notification.NotifyPushCommits(pusher, repo, opts, commits)
if err = models.RemoveDeletedBranchByName(repo.ID, branch); err != nil {