diff --git a/files/files.go b/files/files.go index 5ba9b42..78b2935 100644 --- a/files/files.go +++ b/files/files.go @@ -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 } diff --git a/history/history.go b/history/history.go index 3db87c2..f36db49 100644 --- a/history/history.go +++ b/history/history.go @@ -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 diff --git a/main.go b/main.go index 55b2238..3a64782 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,7 @@ func main() { hyphae.Index(files.HyphaeDir()) user.InitUserDatabase() history.Start() + history.InitGitRepo() shroom.SetHeaderLinks() // Static files: