0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-09 22:51:50 +02:00

Add .org to Git path preparation

markdown files still take priority over org files if both are present
This commit is contained in:
Aly Sewelam 2025-11-24 12:02:44 +02:00
parent 676a7856ac
commit 83353a88bc

View File

@ -55,11 +55,12 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
// prepareGitPath try to find a suitable file path with file name by the given raw wiki name. // prepareGitPath try to find a suitable file path with file name by the given raw wiki name.
// return: existence, prepared file path with name, error // return: existence, prepared file path with name, error
func prepareGitPath(gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath) (bool, string, error) { func prepareGitPath(gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath) (bool, string, error) {
unescaped := string(wikiPath) + ".md" unescapedMd := string(wikiPath) + ".md"
unescapedOrg := string(wikiPath) + ".org"
gitPath := WebPathToGitPath(wikiPath) gitPath := WebPathToGitPath(wikiPath)
// Look for both files // Look for .md, .org, and escaped file
filesInIndex, err := gitRepo.LsTree(defaultWikiBranch, unescaped, gitPath) filesInIndex, err := gitRepo.LsTree(defaultWikiBranch, unescapedMd, unescapedOrg, gitPath)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "Not a valid object name") { if strings.Contains(err.Error(), "Not a valid object name") {
return false, gitPath, nil // branch doesn't exist return false, gitPath, nil // branch doesn't exist
@ -71,9 +72,11 @@ func prepareGitPath(gitRepo *git.Repository, defaultWikiBranch string, wikiPath
foundEscaped := false foundEscaped := false
for _, filename := range filesInIndex { for _, filename := range filesInIndex {
switch filename { switch filename {
case unescaped: // if we find unescaped file (.md or .org) return it
// if we find the unescaped file return it case unescapedMd:
return true, unescaped, nil return true, unescapedMd, nil
case unescapedOrg:
return true, unescapedOrg, nil
case gitPath: case gitPath:
foundEscaped = true foundEscaped = true
} }