mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
fix: compare branches with names diff or patch (#12227)
Closes: Codeberg/Community#2538 Regression of: !5385 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12227 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
parent
1ddd5faa5c
commit
7a86a870c6
4 changed files with 20 additions and 7 deletions
|
|
@ -231,13 +231,6 @@ 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 {
|
||||
|
|
@ -247,6 +240,14 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
|
|||
infos = []string{baseRepo.DefaultBranch, infoPath}
|
||||
}
|
||||
}
|
||||
var isDiff bool
|
||||
infos[1], isDiff = strings.CutSuffix(infos[1], ".diff")
|
||||
ctx.Data["ComparingDiff"] = isDiff
|
||||
if !isDiff {
|
||||
var isPatch bool
|
||||
infos[1], isPatch = strings.CutSuffix(infos[1], ".patch")
|
||||
ctx.Data["ComparingPatch"] = isPatch
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["BaseName"] = baseRepo.OwnerName
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
f27c2b2b03dcab38beaf89b0ab4ff61f6de63441
|
||||
|
|
@ -0,0 +1 @@
|
|||
f27c2b2b03dcab38beaf89b0ab4ff61f6de63441
|
||||
|
|
@ -239,6 +239,16 @@ func TestCompareBranches(t *testing.T) {
|
|||
diffChanges = []string{"test.txt"}
|
||||
|
||||
inspectCompare(t, htmlDoc, diffCount, diffChanges)
|
||||
|
||||
// Branches with name 'diff' or 'patch'
|
||||
req = NewRequest(t, "GET", "/user2/repo16/compare/master..diff")
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
req = NewRequest(t, "GET", "/user2/repo16/compare/master..diff.patch")
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
req = NewRequest(t, "GET", "/user2/repo16/compare/master..patch")
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
req = NewRequest(t, "GET", "/user2/repo16/compare/master..patch.diff")
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
func TestCompareWithPRsDisabled(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue