From da1cedb9ca6758bc205b19b5460e5702a531084c Mon Sep 17 00:00:00 2001 From: Sven Schmalle Date: Fri, 13 Dec 2019 12:30:55 +0100 Subject: [PATCH] =?UTF-8?q?Git-Integration=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++++- main.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b68593a..2d496dd 100644 --- a/README.md +++ b/README.md @@ -23,5 +23,8 @@ Eine `config.json` könnte z.B. wie folgt aussehen: Zum Kompilieren folgende Go-Abhängigkeiten installieren: - `go get github.com/gorilla/mux` + - `go get gopkg.in/src-d/go-git.v4` -Die Buildscripte liegen im Unterordner `build` \ No newline at end of file +Die Buildscripte liegen im Unterordner `build` + +Download der Binarys unter: [https://nc.masilux.de/index.php/s/dGRdPsa6XPPiyQk](https://nc.masilux.de/index.php/s/dGRdPsa6XPPiyQk) \ No newline at end of file diff --git a/main.go b/main.go index 2479430..51c4ca7 100644 --- a/main.go +++ b/main.go @@ -12,8 +12,11 @@ import ( "path" "path/filepath" "strings" + "time" "github.com/gorilla/mux" + "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing/object" ) var config = readConfig("") @@ -52,6 +55,14 @@ func main() { check(err) } + // Git Repository Init + if !directoryExists(path.Join(config.DataPath, ".git")) { + + _, err := git.PlainInit(config.DataPath, false) + check(err) + GitCommit("Initial Wiki Commit") + } + router := mux.NewRouter() router.HandleFunc("/p/{pagename:.*}", getRawPage).Methods("GET") router.HandleFunc("/{pagename:.*}", getHTMLPage).Methods("GET") @@ -92,7 +103,7 @@ func getHTMLPage(w http.ResponseWriter, r *http.Request) { } } - if info.Name() != "data" && info.Name() != "start.md" && info.Name() != "sidebar.md" && info.Name() != "hilfe.md" { + if info.Name() != "data" && !strings.HasPrefix(tmpPath, "/.git") && info.Name() != "start.md" && info.Name() != "sidebar.md" && info.Name() != "hilfe.md" { if !strings.HasSuffix(info.Name(), ".md") { sidebarAusgabe = sidebarAusgabe + sidebarTABs + "* [" + strings.TrimSuffix(info.Name(), ".md") + "](" + strings.TrimSuffix(tmpPath, ".md") + "/start) \r\n" } else { @@ -158,6 +169,9 @@ func postHTMLPage(w http.ResponseWriter, r *http.Request) { check(err) fw.Flush() + // Git Commit + GitCommit("Auto-Commit Page: " + pPageName) + json.NewEncoder(w).Encode("OK") } @@ -215,3 +229,38 @@ func readConfig(filename string) *Configuration { } return conf } + +func GitCommit(CommitText string) { + + // Git Repo öffnen + repo, err := git.PlainOpen(config.DataPath) + check(err) + + // Working Tree setzen + wt, err := repo.Worktree() + check(err) + + // Alle Dateien zum Working Tree hinzufügen + _, err = wt.Add(".") + check(err) + + // Status ausgeben + //status, err := wt.Status() + //check(err) + //fmt.Println(status) + + // Neuen Commit Erstellen + _, err = wt.Commit(CommitText, &git.CommitOptions{ + Author: &object.Signature{ + Name: "GoWiki", + Email: "gowiki@local.org", + When: time.Now(), + }, + }) + check(err) + + // Commit infos anzeigen + //obj, err := repo.CommitObject(commit) + //check(err) + //fmt.Println(obj) +}