Skip to content

Fixes diff on merged pull requests #7171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions modules/git/repo_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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.
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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") {
Expand All @@ -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
Expand Down