]> source.dussan.org Git - gitea.git/commitdiff
Fixes diff on merged pull requests (#7171)
authorMario Lubenka <mario.lubenka@googlemail.com>
Tue, 11 Jun 2019 23:32:08 +0000 (01:32 +0200)
committertechknowlogick <hello@techknowlogick.com>
Tue, 11 Jun 2019 23:32:08 +0000 (19:32 -0400)
models/pull.go
modules/git/repo_compare.go
routers/repo/pull.go

index 5ac1126314d1a543260213907233b4e4242ac620..1f03dd9b0f5a9f9abf67552548d860a352c00504 100644 (file)
@@ -1144,7 +1144,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
        defer func() {
                headGitRepo.RemoveRemote(tmpRemote)
        }()
-       pr.MergeBase, err = headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch)
+       pr.MergeBase, _, err = headGitRepo.GetMergeBase(tmpRemote, pr.BaseBranch, pr.HeadBranch)
        if err != nil {
                return fmt.Errorf("GetMergeBase: %v", err)
        } else if err = pr.Update(); err != nil {
index e7a1d72a8592b03fd4dde37c8cda844a46bad073..42f0b9ad0cd766486c42900c23769b01b16983e8 100644 (file)
@@ -22,8 +22,8 @@ type CompareInfo struct {
        NumFiles  int
 }
 
-// GetMergeBase checks and returns merge base of two branches.
-func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (string, error) {
+// GetMergeBase checks and returns merge base of two branches and the reference used as base.
+func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (string, string, error) {
        if tmpRemote == "" {
                tmpRemote = "origin"
        }
@@ -38,7 +38,7 @@ func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (strin
        }
 
        stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path)
-       return strings.TrimSpace(stdout), err
+       return strings.TrimSpace(stdout), base, err
 }
 
 // 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)
        }
 
        compareInfo := new(CompareInfo)
-       compareInfo.MergeBase, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
+       compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
        if err == nil {
                // We have a common base
                logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
index 182f715545237d392947090a0223371b09cd5e6c..71c684356db2a6263000892840248fb527071c58 100644 (file)
@@ -286,7 +286,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
        setMergeTarget(ctx, pull)
        ctx.Data["HasMerged"] = true
 
-       prInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
+       compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
                pull.MergeBase, pull.GetGitRefName())
 
        if err != nil {
@@ -301,9 +301,9 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
                ctx.ServerError("GetCompareInfo", err)
                return nil
        }
-       ctx.Data["NumCommits"] = prInfo.Commits.Len()
-       ctx.Data["NumFiles"] = prInfo.NumFiles
-       return prInfo
+       ctx.Data["NumCommits"] = compareInfo.Commits.Len()
+       ctx.Data["NumFiles"] = compareInfo.NumFiles
+       return compareInfo
 }
 
 // PrepareViewPullInfo show meta information for a pull request preview page
@@ -336,7 +336,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
                return nil
        }
 
-       prInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
+       compareInfo, err := headGitRepo.GetCompareInfo(models.RepoPath(repo.Owner.Name, repo.Name),
                pull.BaseBranch, pull.HeadBranch)
        if err != nil {
                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
                ctx.Data["ConflictedFiles"] = pull.ConflictedFiles
        }
 
-       ctx.Data["NumCommits"] = prInfo.Commits.Len()
-       ctx.Data["NumFiles"] = prInfo.NumFiles
-       return prInfo
+       ctx.Data["NumCommits"] = compareInfo.Commits.Len()
+       ctx.Data["NumFiles"] = compareInfo.NumFiles
+       return compareInfo
 }
 
 // ViewPullCommits show commits for a pull request