Skip to content
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

Display PR commits and diffs using base repo rather than forked #3648

Merged
merged 3 commits into from
Dec 18, 2019
Merged
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
105 changes: 35 additions & 70 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,30 +438,23 @@ func ViewPullCommits(ctx *context.Context) {
pull := issue.PullRequest

var commits *list.List
var prInfo *git.CompareInfo
if pull.HasMerged {
prInfo := PrepareMergedViewPullInfo(ctx, issue)
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullCommits", nil)
return
}
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
commits = prInfo.Commits
prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
prInfo := PrepareViewPullInfo(ctx, issue)
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullCommits", nil)
return
}
ctx.Data["Username"] = pull.MustHeadUserName()
ctx.Data["Reponame"] = pull.HeadRepo.Name
commits = prInfo.Commits
prInfo = PrepareViewPullInfo(ctx, issue)
}

if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullCommits", nil)
return
}

ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
commits = prInfo.Commits
commits = models.ValidateCommitsWithEmails(commits)
commits = models.ParseCommitsWithSignature(commits)
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
Expand Down Expand Up @@ -497,63 +490,35 @@ func ViewPullFiles(ctx *context.Context) {
)

var headTarget string
var prInfo *git.CompareInfo
if pull.HasMerged {
prInfo := PrepareMergedViewPullInfo(ctx, issue)
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullFiles", nil)
return
}

diffRepoPath = ctx.Repo.GitRepo.Path
gitRepo = ctx.Repo.GitRepo

headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
}

startCommitID = prInfo.MergeBase
endCommitID = headCommitID

headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
prInfo := PrepareViewPullInfo(ctx, issue)
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullFiles", nil)
return
}
prInfo = PrepareViewPullInfo(ctx, issue)
}

headRepoPath := pull.HeadRepo.RepoPath()
if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullFiles", nil)
return
}

headGitRepo, err := git.OpenRepository(headRepoPath)
if err != nil {
ctx.ServerError("OpenRepository", err)
return
}
defer headGitRepo.Close()
diffRepoPath = ctx.Repo.GitRepo.Path
gitRepo = ctx.Repo.GitRepo

headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
if err != nil {
ctx.ServerError("GetBranchCommitID", err)
return
}
headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
}

diffRepoPath = headRepoPath
startCommitID = prInfo.MergeBase
endCommitID = headCommitID
gitRepo = headGitRepo
startCommitID = prInfo.MergeBase
endCommitID = headCommitID

headTarget = path.Join(pull.MustHeadUserName(), pull.HeadRepo.Name)
ctx.Data["Username"] = pull.MustHeadUserName()
ctx.Data["Reponame"] = pull.HeadRepo.Name
}
headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["AfterCommitID"] = endCommitID

diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,
Expand Down