Skip to content

Commit

Permalink
Fix 500 on first wiki page
Browse files Browse the repository at this point in the history
There is a mistake in go-gitea#16319 and go-gitea#16487 which means that the first time
a wiki page is created a 500 is reported because the `master` branch is
not in existence in that wiki yet.

This PR simply checks for this error and returns not found.

Fix go-gitea#16584

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jul 31, 2021
1 parent e830650 commit 65307e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions services/wiki/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
// Look for both files
filesInIndex, err := gitRepo.LsTree("master", unescaped, escaped)
if err != nil {
if strings.Contains(err.Error(), "Not a valid object name master") {
return false, escaped, nil
}
log.Error("%v", err)
return false, escaped, err
}
Expand Down
28 changes: 28 additions & 0 deletions services/wiki/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
package wiki

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -261,3 +264,28 @@ func TestPrepareWikiFileName(t *testing.T) {
})
}
}

func TestPrepareWikiFileName_FirstPage(t *testing.T) {
models.PrepareTestEnv(t)

// Now create a temporaryDirectory
tmpDir, err := ioutil.TempDir("", "empty-wiki")
assert.NoError(t, err)
defer func() {
if _, err := os.Stat(tmpDir); !os.IsNotExist(err) {
_ = util.RemoveAll(tmpDir)
}
}()

err = git.InitRepository(tmpDir, true)
assert.NoError(t, err)

gitRepo, err := git.OpenRepository(tmpDir)
defer gitRepo.Close()
assert.NoError(t, err)

existence, newWikiPath, err := prepareWikiFileName(gitRepo, "Home")
assert.False(t, existence)
assert.NoError(t, err)
assert.Equal(t, "Home.md", newWikiPath)
}

0 comments on commit 65307e7

Please sign in to comment.