Skip to content

Commit 1608f63

Browse files
saithotechknowlogick
authored andcommitted
Fixes diff on merged pull requests (#7171)
1 parent 499a8a1 commit 1608f63

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

models/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
11441144
defer func() {
11451145
headGitRepo.RemoveRemote(tmpRemote)
11461146
}()
1147-
pr.MergeBase, err = headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch)
1147+
pr.MergeBase, _, err = headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch)
11481148
if err != nil {
11491149
return fmt.Errorf("GetMergeBase: %v", err)
11501150
} else if err = pr.Update(); err != nil {

modules/git/repo_compare.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ type CompareInfo struct {
2222
NumFiles int
2323
}
2424

25-
// GetMergeBase checks and returns merge base of two branches.
26-
func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (string, error) {
25+
// GetMergeBase checks and returns merge base of two branches and the reference used as base.
26+
func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (string, string, error) {
2727
if tmpRemote == "" {
2828
tmpRemote = "origin"
2929
}
@@ -38,7 +38,7 @@ func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (strin
3838
}
3939

4040
stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path)
41-
return strings.TrimSpace(stdout), err
41+
return strings.TrimSpace(stdout), base, err
4242
}
4343

4444
// GetCompareInfo generates and returns compare information between base and head branches of repositories.
@@ -59,7 +59,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
5959
}
6060

6161
compareInfo := new(CompareInfo)
62-
compareInfo.MergeBase, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
62+
compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
6363
if err == nil {
6464
// We have a common base
6565
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)

routers/repo/pull.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
286286
setMergeTarget(ctx, pull)
287287
ctx.Data["HasMerged"] = true
288288

289-
prInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
289+
compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
290290
pull.MergeBase, pull.GetGitRefName())
291291

292292
if err != nil {
@@ -301,9 +301,9 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
301301
ctx.ServerError("GetCompareInfo", err)
302302
return nil
303303
}
304-
ctx.Data["NumCommits"] = prInfo.Commits.Len()
305-
ctx.Data["NumFiles"] = prInfo.NumFiles
306-
return prInfo
304+
ctx.Data["NumCommits"] = compareInfo.Commits.Len()
305+
ctx.Data["NumFiles"] = compareInfo.NumFiles
306+
return compareInfo
307307
}
308308

309309
// PrepareViewPullInfo show meta information for a pull request preview page
@@ -336,7 +336,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
336336
return nil
337337
}
338338

339-
prInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
339+
compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
340340
pull.BaseBranch, pull.HeadBranch)
341341
if err != nil {
342342
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
@@ -361,9 +361,9 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
361361
ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
362362
}
363363

364-
ctx.Data["NumCommits"] = prInfo.Commits.Len()
365-
ctx.Data["NumFiles"] = prInfo.NumFiles
366-
return prInfo
364+
ctx.Data["NumCommits"] = compareInfo.Commits.Len()
365+
ctx.Data["NumFiles"] = compareInfo.NumFiles
366+
return compareInfo
367367
}
368368

369369
// ViewPullCommits show commits for a pull request

0 commit comments

Comments
 (0)