pull/7408/merge
micronet24 2025-03-13 16:49:46 +01:00 committed by GitHub
commit 7ed495fb58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View File

@ -119,6 +119,8 @@ ENABLE_RAW_FILE_RENDER_MODE = false
COMMITS_FETCH_CONCURRENCY = 0
; Default branch name when creating new repositories.
DEFAULT_BRANCH = master
; Wether to automatically create wiki repos if they do not exist, but are enabled
AUTOCREATE_WIKI = true
[repository.editor]
; List of file extensions that should have line wraps in the CodeMirror editor.

View File

@ -10,9 +10,11 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"time"
"github.com/gogs/git-module"
"github.com/unknwon/com"
"github.com/urfave/cli"
log "unknwon.dev/clog/v2"
@ -132,6 +134,8 @@ var allowedCommands = map[string]database.AccessMode{
"git-receive-pack": database.AccessModeWrite,
}
var reWikiRepo = regexp.MustCompile("\\.wiki(?:\\.git)?$")
func runServ(c *cli.Context) error {
ctx := context.Background()
setup(c, "serv.log", true)
@ -254,6 +258,17 @@ func runServ(c *cli.Context) error {
verb = strings.Replace(verb, "-", " ", 1)
}
repoFsPath := fmt.Sprintf("%s/%s.git", conf.Repository.Root, strings.TrimSuffix(repoFullName, ".git"))
if _, err := os.Stat(repoFsPath); err != nil {
if conf.Repository.AutocreateWiki && repo.EnableWiki && reWikiRepo.MatchString(repoFullName) && requestMode == db.AccessModeWrite {
if err = git.Init(repoFsPath, git.InitOptions{ Bare: true }); err != nil {
fail("Internal error", "Failed to initialize new git repo %s: %v", repoFullName, err)
}
} else {
fail("Internal error", "Repository %v doesn't exist!", repoFullName)
}
}
var gitCmd *exec.Cmd
verbs := strings.Split(verb, " ")
if len(verbs) == 2 {

View File

@ -323,6 +323,7 @@ type RepositoryOpts struct {
EnableRawFileRenderMode bool
CommitsFetchConcurrency int
DefaultBranch string
AutocreateWiki bool
// Repository editor settings
Editor struct {