Git-Integration hinzugefügt
This commit is contained in:
		| @@ -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`  | ||||
| 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) | ||||
							
								
								
									
										51
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								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) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user