diff options
author | zeripath <art27@cantab.net> | 2020-03-31 14:42:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 16:42:44 +0300 |
commit | 2c25e75dca62850ddc328ed46c7b7d27b61be90b (patch) | |
tree | f48395e914269304e236d032f0fc642cd5de62a7 /models/migrations/v128.go | |
parent | 73cf0e2614263c8c4ad6d55d06e753b28d2b6091 (diff) | |
download | gitea-2c25e75dca62850ddc328ed46c7b7d27b61be90b.tar.gz gitea-2c25e75dca62850ddc328ed46c7b7d27b61be90b.zip |
Various Merge Base fixes (#10786)
* Fix broken merge base migration v128 for merged PR
* Allow PRs with deleted base branches to still show diff
* as per @lunny
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/migrations/v128.go')
-rw-r--r-- | models/migrations/v128.go | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/models/migrations/v128.go b/models/migrations/v128.go index 557282bf28..1f4bc20527 100644 --- a/models/migrations/v128.go +++ b/models/migrations/v128.go @@ -53,7 +53,7 @@ func fixMergeBase(x *xorm.Engine) error { break } - i += 50 + i += len(prs) for _, pr := range prs { baseRepo := &Repository{ID: pr.BaseRepoID} has, err := x.Table("repository").Get(baseRepo) @@ -81,10 +81,22 @@ func fixMergeBase(x *xorm.Engine) error { } } } else { - var err error - pr.MergeBase, err = git.NewCommand("merge-base", "--", pr.MergedCommitID+"^", gitRefName).RunInDir(repoPath) + parentsString, err := git.NewCommand("rev-list", "--parents", "-n", "1", pr.MergedCommitID).RunInDir(repoPath) + if err != nil { + log.Error("Unable to get parents for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err) + continue + } + parents := strings.Split(strings.TrimSpace(parentsString), " ") + if len(parents) < 2 { + continue + } + + args := append([]string{"merge-base", "--"}, parents[1:]...) + args = append(args, gitRefName) + + pr.MergeBase, err = git.NewCommand(args...).RunInDir(repoPath) if err != nil { - log.Error("Unable to get merge base for merged PR ID %d, Index %d in %s/%s. Error: %", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err) + log.Error("Unable to get merge base for merged PR ID %d, Index %d in %s/%s. Error: %v", pr.ID, pr.Index, baseRepo.OwnerName, baseRepo.Name, err) continue } } |