0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-19 02:00:58 +02:00

support tag and branch names with ends with .diff and .patch

This commit is contained in:
badhezi 2025-05-14 13:59:51 +03:00
parent 17c860e97d
commit 3274b844c6

View File

@ -231,18 +231,28 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
var infos []string
// Handle possible suffixes: .diff or .patch
if strings.HasSuffix(infoPath, ".diff") {
ci.RawDiffType = git.RawDiffNormal
infoPath = strings.TrimSuffix(infoPath, ".diff")
} else if strings.HasSuffix(infoPath, ".patch") {
ci.RawDiffType = git.RawDiffPatch
infoPath = strings.TrimSuffix(infoPath, ".patch")
}
if infoPath == "" {
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
} else {
// check if head is a branch or tag on ly infoPath ends with .diff or .patch
if strings.HasSuffix(infoPath, ".diff") || strings.HasSuffix(infoPath, ".patch") {
infos = strings.SplitN(infoPath, "...", 2)
if len(infos) != 2 {
infos = strings.SplitN(infoPath, "..", 2) // match github behavior
}
ref2IsBranch := gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, infos[1])
ref2IsTag := gitrepo.IsTagExist(ctx, ctx.Repo.Repository, infos[1])
if !ref2IsBranch && !ref2IsTag {
if strings.HasSuffix(infoPath, ".diff") {
ci.RawDiffType = git.RawDiffNormal
infoPath = strings.TrimSuffix(infoPath, ".diff")
} else if strings.HasSuffix(infoPath, ".patch") {
ci.RawDiffType = git.RawDiffPatch
infoPath = strings.TrimSuffix(infoPath, ".patch")
}
}
}
infos = strings.SplitN(infoPath, "...", 2)
if len(infos) != 2 {
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {