1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-05 17:40:26 +00:00

Automatically init Git repo if not already

This commit is contained in:
handlerug 2021-06-19 13:04:04 +07:00
parent 7b2423ec40
commit 919f844468
No known key found for this signature in database
GPG Key ID: 38009F0605051491
3 changed files with 29 additions and 7 deletions

View File

@ -3,7 +3,7 @@ package files
import (
"os"
"path"
"path/filepath"
"github.com/bouncepaw/mycorrhiza/cfg"
)
@ -46,24 +46,24 @@ func PrepareWikiRoot() error {
return err
}
paths.cacheDir = path.Join(cfg.WikiDir, "cache")
paths.cacheDir = filepath.Join(cfg.WikiDir, "cache")
if err := os.MkdirAll(paths.cacheDir, os.ModeDir|0777); err != nil {
return err
}
paths.gitRepo = path.Join(cfg.WikiDir, "wiki.git")
paths.gitRepo = filepath.Join(cfg.WikiDir, "wiki.git")
if err := os.MkdirAll(paths.gitRepo, os.ModeDir|0777); err != nil {
return err
}
paths.staticFiles = path.Join(cfg.WikiDir, "static")
paths.staticFiles = filepath.Join(cfg.WikiDir, "static")
if err := os.MkdirAll(paths.staticFiles, os.ModeDir|0777); err != nil {
return err
}
paths.tokensJSON = path.Join(paths.cacheDir, "tokens.json")
paths.fixedCredentialsJSON = path.Join(cfg.WikiDir, "fixed-users.json")
paths.registrationCredentialsJSON = path.Join(paths.cacheDir, "registered-users.json")
paths.tokensJSON = filepath.Join(paths.cacheDir, "tokens.json")
paths.fixedCredentialsJSON = filepath.Join(cfg.WikiDir, "fixed-users.json")
paths.registrationCredentialsJSON = filepath.Join(paths.cacheDir, "registered-users.json")
return nil
}

View File

@ -7,6 +7,7 @@ import (
"html"
"log"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
@ -32,6 +33,26 @@ func Start() {
gitpath = path
}
func InitGitRepo() {
// Detect if the Git repo directory is a Git repository
isGitRepo := true
buf, err := gitsh("rev-parse", "--git-dir")
if err != nil {
isGitRepo = false
}
if isGitRepo {
gitDir := buf.String()
if filepath.IsAbs(gitDir) && !filepath.HasPrefix(gitDir, files.HyphaeDir()) {
isGitRepo = false
}
}
if !isGitRepo {
log.Println("Initializing Git repo at", files.HyphaeDir())
gitsh("init")
gitsh("config", "core.quotePath", "false")
}
}
// Revision represents a revision, duh. Hash is usually short. Username is extracted from email.
type Revision struct {
Hash string

View File

@ -41,6 +41,7 @@ func main() {
hyphae.Index(files.HyphaeDir())
user.InitUserDatabase()
history.Start()
history.InitGitRepo()
shroom.SetHeaderLinks()
// Static files: