mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-23 02:21:59 -05:00
Add patch/diff compare download
This commit is contained in:
parent
5132854603
commit
9195d6a318
3 changed files with 15 additions and 10 deletions
|
@ -232,9 +232,9 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
|
|||
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
|
||||
} else {
|
||||
infoPath, isDiff := strings.CutSuffix(infoPath, ".diff")
|
||||
ctx.Data["DownloadDiff"] = isDiff
|
||||
ctx.Data["ComparingDiff"] = isDiff
|
||||
infoPath, isPatch := strings.CutSuffix(infoPath, ".patch")
|
||||
ctx.Data["DownloadPatch"] = isPatch
|
||||
ctx.Data["ComparingPatch"] = isPatch
|
||||
infos = strings.SplitN(infoPath, "...", 2)
|
||||
if len(infos) != 2 {
|
||||
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
|
||||
|
@ -721,18 +721,18 @@ func CompareDiff(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.Data["DownloadDiff"].(bool) {
|
||||
if ctx.Data["ComparingDiff"].(bool) {
|
||||
err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch,git.RawDiffNormal,"", ctx.Resp)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiff", err)
|
||||
ctx.ServerError("ComparingDiff", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ctx.Data["DownloadPatch"].(bool) {
|
||||
if ctx.Data["ComparingPatch"].(bool) {
|
||||
err := git.GetRepoRawDiffForFile(ci.HeadGitRepo, ci.BaseBranch, ci.HeadBranch,git.RawDiffPatch,"", ctx.Resp)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetPatch", err)
|
||||
ctx.ServerError("ComparingPatch", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -822,7 +822,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)
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
{{else if .Commit.ID.String}}
|
||||
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.patch" download="{{ShortSha .Commit.ID.String}}.patch">{{ctx.Locale.Tr "repo.diff.download_patch"}}</a>
|
||||
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.diff" download="{{ShortSha .Commit.ID.String}}.diff">{{ctx.Locale.Tr "repo.diff.download_diff"}}</a>
|
||||
{{else if .Diff}}
|
||||
<a class="item" href="{{$.RepoLink}}/compare/{{.Comparing}}.patch" download="{{.Comparing}}.patch">{{ctx.Locale.Tr "repo.diff.download_patch"}}</a>
|
||||
<a class="item" href="{{$.RepoLink}}/compare/{{.Comparing}}.diff" download="{{.Comparing}}.diff">{{ctx.Locale.Tr "repo.diff.download_diff"}}</a>
|
||||
{{end}}
|
||||
<a id="expand-files-btn" class="item">{{ctx.Locale.Tr "repo.pulls.expand_files"}}</a>
|
||||
<a id="collapse-files-btn" class="item">{{ctx.Locale.Tr "repo.pulls.collapse_files"}}</a>
|
||||
|
|
|
@ -75,11 +75,11 @@ func TestComparePatchAndDiffMenuEntries(t *testing.T) {
|
|||
req := NewRequest(t, "GET", "/user2/repo-release/compare/v1.0...v2.0")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
diffOptions := htmlDoc.doc.Find("[data-tooltip-content=\"Diff options\"]")
|
||||
downloadOptions := htmlDoc.doc.Find("a.item[download]")
|
||||
|
||||
var patchDownloadEntryPresent bool
|
||||
var diffDownloadEntryPresent bool
|
||||
diffOptions.Children().Each(func (idx int, c *goquery.Selection) {
|
||||
downloadOptions.Each(func (idx int, c *goquery.Selection) {
|
||||
value, exists := c.Attr("download")
|
||||
if exists && strings.HasSuffix(value, ".patch") {
|
||||
patchDownloadEntryPresent = true
|
||||
|
@ -88,6 +88,7 @@ func TestComparePatchAndDiffMenuEntries(t *testing.T) {
|
|||
if exists && strings.HasSuffix(value, ".diff") {
|
||||
diffDownloadEntryPresent = true
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
assert.True(t, patchDownloadEntryPresent, "Patch file download entry should be present")
|
||||
|
|
Loading…
Reference in a new issue