Fixes diff on merged pull requests (#7171)

tokarchuk/v1.17
Mario Lubenka 5 years ago committed by techknowlogick
parent 499a8a1cdd
commit 1608f63e39
  1. 2
      models/pull.go
  2. 8
      modules/git/repo_compare.go
  3. 16
      routers/repo/pull.go

@ -1144,7 +1144,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
defer func() { defer func() {
headGitRepo.RemoveRemote(tmpRemote) 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 { if err != nil {
return fmt.Errorf("GetMergeBase: %v", err) return fmt.Errorf("GetMergeBase: %v", err)
} else if err = pr.Update(); err != nil { } else if err = pr.Update(); err != nil {

@ -22,8 +22,8 @@ type CompareInfo struct {
NumFiles int NumFiles int
} }
// GetMergeBase checks and returns merge base of two branches. // 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, error) { func (repo *Repository) GetMergeBase(tmpRemote string, base, head string) (string, string, error) {
if tmpRemote == "" { if tmpRemote == "" {
tmpRemote = "origin" 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) 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. // 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 := new(CompareInfo)
compareInfo.MergeBase, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch) compareInfo.MergeBase, remoteBranch, err = repo.GetMergeBase(tmpRemote, baseBranch, headBranch)
if err == nil { if err == nil {
// We have a common base // We have a common base
logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path) logs, err := NewCommand("log", compareInfo.MergeBase+"..."+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)

@ -286,7 +286,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
setMergeTarget(ctx, pull) setMergeTarget(ctx, pull)
ctx.Data["HasMerged"] = true 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()) pull.MergeBase, pull.GetGitRefName())
if err != nil { if err != nil {
@ -301,9 +301,9 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
ctx.ServerError("GetCompareInfo", err) ctx.ServerError("GetCompareInfo", err)
return nil return nil
} }
ctx.Data["NumCommits"] = prInfo.Commits.Len() ctx.Data["NumCommits"] = compareInfo.Commits.Len()
ctx.Data["NumFiles"] = prInfo.NumFiles ctx.Data["NumFiles"] = compareInfo.NumFiles
return prInfo return compareInfo
} }
// PrepareViewPullInfo show meta information for a pull request preview page // 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 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) pull.BaseBranch, pull.HeadBranch)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") { 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["ConflictedFiles"] = pull.ConflictedFiles
} }
ctx.Data["NumCommits"] = prInfo.Commits.Len() ctx.Data["NumCommits"] = compareInfo.Commits.Len()
ctx.Data["NumFiles"] = prInfo.NumFiles ctx.Data["NumFiles"] = compareInfo.NumFiles
return prInfo return compareInfo
} }
// ViewPullCommits show commits for a pull request // ViewPullCommits show commits for a pull request

Loading…
Cancel
Save