Change PR commits and diffs to use base repo rather than forked (#3648)

Change the repository referenced when displaying commits or diffs in
pull request to the base repository.  The forked repository may not be
readable by users who can read the base repository.  See discussion for
(#3356).
forgejo
Keith Rutkowski 5 years ago committed by techknowlogick
parent d66ae50fd5
commit 21f84a6315

@ -438,30 +438,23 @@ func ViewPullCommits(ctx *context.Context) {
pull := issue.PullRequest pull := issue.PullRequest
var commits *list.List var commits *list.List
var prInfo *git.CompareInfo
if pull.HasMerged { if pull.HasMerged {
prInfo := PrepareMergedViewPullInfo(ctx, issue) 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
} else { } else {
prInfo := PrepareViewPullInfo(ctx, issue) 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
} }
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.ValidateCommitsWithEmails(commits)
commits = models.ParseCommitsWithSignature(commits) commits = models.ParseCommitsWithSignature(commits)
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository) commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
@ -497,63 +490,35 @@ func ViewPullFiles(ctx *context.Context) {
) )
var headTarget string var headTarget string
var prInfo *git.CompareInfo
if pull.HasMerged { if pull.HasMerged {
prInfo := PrepareMergedViewPullInfo(ctx, issue) 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
} else { } else {
prInfo := PrepareViewPullInfo(ctx, issue) prInfo = PrepareViewPullInfo(ctx, issue)
if ctx.Written() { }
return
} else if prInfo == nil {
ctx.NotFound("ViewPullFiles", nil)
return
}
headRepoPath := pull.HeadRepo.RepoPath() if ctx.Written() {
return
} else if prInfo == nil {
ctx.NotFound("ViewPullFiles", nil)
return
}
headGitRepo, err := git.OpenRepository(headRepoPath) diffRepoPath = ctx.Repo.GitRepo.Path
if err != nil { gitRepo = ctx.Repo.GitRepo
ctx.ServerError("OpenRepository", err)
return
}
defer headGitRepo.Close()
headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch) headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil { if err != nil {
ctx.ServerError("GetBranchCommitID", err) ctx.ServerError("GetRefCommitID", err)
return return
} }
diffRepoPath = headRepoPath startCommitID = prInfo.MergeBase
startCommitID = prInfo.MergeBase endCommitID = headCommitID
endCommitID = headCommitID
gitRepo = headGitRepo
headTarget = path.Join(pull.MustHeadUserName(), pull.HeadRepo.Name) headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
ctx.Data["Username"] = pull.MustHeadUserName() ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = pull.HeadRepo.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name
}
ctx.Data["AfterCommitID"] = endCommitID ctx.Data["AfterCommitID"] = endCommitID
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath, diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,

Loading…
Cancel
Save