forked from kevadesu/forgejo
Merge pull request 'Permit to download patch and diff file between tags and branches' (#5385) from mirkoperillo/forgejo:issue-3728 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5385 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
da5445ac87
3 changed files with 137 additions and 1 deletions
|
@ -231,6 +231,13 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
|
|||
if infoPath == "" {
|
||||
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
|
||||
} else {
|
||||
infoPath, isDiff := strings.CutSuffix(infoPath, ".diff")
|
||||
ctx.Data["ComparingDiff"] = isDiff
|
||||
if !isDiff {
|
||||
var isPatch bool
|
||||
infoPath, isPatch = strings.CutSuffix(infoPath, ".patch")
|
||||
ctx.Data["ComparingPatch"] = isPatch
|
||||
}
|
||||
infos = strings.SplitN(infoPath, "...", 2)
|
||||
if len(infos) != 2 {
|
||||
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
|
||||
|
@ -717,6 +724,22 @@ func CompareDiff(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.Data["ComparingDiff"] != nil && ctx.Data["ComparingDiff"].(bool) {
|
||||
err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, git.RawDiffNormal, "", ctx.Resp)
|
||||
if err != nil {
|
||||
ctx.ServerError("ComparingDiff", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.Data["ComparingPatch"] != nil && ctx.Data["ComparingPatch"].(bool) {
|
||||
err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch, git.RawDiffPatch, "", ctx.Resp)
|
||||
if err != nil {
|
||||
ctx.ServerError("ComparingPatch", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
|
||||
ctx.Data["DirectComparison"] = ci.DirectComparison
|
||||
ctx.Data["OtherCompareSeparator"] = ".."
|
||||
|
@ -802,7 +825,8 @@ func CompareDiff(ctx *context.Context) {
|
|||
if ci.DirectComparison {
|
||||
separator = ".."
|
||||
}
|
||||
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID)
|
||||
ctx.Data["Comparing"] = base.ShortSha(beforeCommitID) + separator + base.ShortSha(afterCommitID)
|
||||
ctx.Data["Title"] = "Comparing " + ctx.Data["Comparing"].(string)
|
||||
|
||||
ctx.Data["IsDiffCompare"] = true
|
||||
_, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue