mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 05:54:38 +02:00
support tag and branch names with ends with .diff and .patch
This commit is contained in:
parent
17c860e97d
commit
3274b844c6
@ -231,7 +231,18 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
|
|||||||
|
|
||||||
var infos []string
|
var infos []string
|
||||||
|
|
||||||
// Handle possible suffixes: .diff or .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") {
|
if strings.HasSuffix(infoPath, ".diff") {
|
||||||
ci.RawDiffType = git.RawDiffNormal
|
ci.RawDiffType = git.RawDiffNormal
|
||||||
infoPath = strings.TrimSuffix(infoPath, ".diff")
|
infoPath = strings.TrimSuffix(infoPath, ".diff")
|
||||||
@ -239,10 +250,9 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
|
|||||||
ci.RawDiffType = git.RawDiffPatch
|
ci.RawDiffType = git.RawDiffPatch
|
||||||
infoPath = strings.TrimSuffix(infoPath, ".patch")
|
infoPath = strings.TrimSuffix(infoPath, ".patch")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if infoPath == "" {
|
|
||||||
infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
|
|
||||||
} else {
|
|
||||||
infos = strings.SplitN(infoPath, "...", 2)
|
infos = strings.SplitN(infoPath, "...", 2)
|
||||||
if len(infos) != 2 {
|
if len(infos) != 2 {
|
||||||
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
|
if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user