|
|
|
@ -1,8 +1,10 @@
|
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bufio" |
|
|
|
|
"fmt" |
|
|
|
|
"log" |
|
|
|
|
"os" |
|
|
|
|
"os/exec" |
|
|
|
|
"path/filepath" |
|
|
|
|
"runtime" |
|
|
|
@ -60,7 +62,7 @@ func gitExePath(hook *Hook) string {
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
startTime := time.Now() |
|
|
|
|
logLines := "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n" + startTime.Format(time.RFC822) + "\n" |
|
|
|
|
logLines := fmt.Sprintf("~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\nSANDPOINTS GITHOOK (%s)\n\n", version) |
|
|
|
|
|
|
|
|
|
// init global struct/variables
|
|
|
|
|
var hook *Hook |
|
|
|
@ -75,13 +77,16 @@ func main() {
|
|
|
|
|
hook.Gogit = true |
|
|
|
|
hook.PublicHTMLPath = filepath.Join("/var", "www", "html", "sandpoints") |
|
|
|
|
|
|
|
|
|
// hookExe, err := os.Executable()
|
|
|
|
|
// check(err)
|
|
|
|
|
// hook.ExecutablePath = filepath.Dir(hookExe)
|
|
|
|
|
hookExe, err := os.Executable() |
|
|
|
|
check(err) |
|
|
|
|
hook.ExecutablePath = filepath.Dir(hookExe) |
|
|
|
|
// hook.ExecutablePath = "/home/m/Downloads/SimpleSandpoints/.git/hooks"
|
|
|
|
|
// hook.ExecutablePath = "/home/m/gitea-repositories/sandpoints/dev.git/hooks/post-receive.d"
|
|
|
|
|
hook.ExecutablePath = "/home/m/gitea-repositories/sandpoints/simplesandpoints.git/hooks/post-receive.d" |
|
|
|
|
hookContext(hook) |
|
|
|
|
// hook.ExecutablePath = "/home/m/gitea-repositories/sandpoints/simplesandpoints.git/hooks/post-receive.d"
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin) |
|
|
|
|
scanner.Scan() |
|
|
|
|
scannerTxt := scanner.Text() |
|
|
|
|
hookContext(hook, scannerTxt) |
|
|
|
|
gitPath := gitExePath(hook) |
|
|
|
|
giqi = &giq.Gogit{} |
|
|
|
|
// enforce go-git if mocking hook.ExecutablePath
|
|
|
|
@ -93,38 +98,39 @@ func main() {
|
|
|
|
|
git = giqi.GitStruct(hook.ExecutablePath, hook.Context, hook.Stdinput, gitPath) |
|
|
|
|
hook.Publish = git.Publish |
|
|
|
|
hugo.SourceDir = git.RepoPath |
|
|
|
|
// hugo.DestinationDir =
|
|
|
|
|
|
|
|
|
|
if git.IsBare { |
|
|
|
|
giqi.AddBareWorktree(git.RepoPath, git.IndexPath, git.Worktree, gitPath) |
|
|
|
|
defer giqi.RemoveBareWorktree(git.RepoPath, git.IndexPath, git.Worktree, gitPath) |
|
|
|
|
hugo.SourceDir = git.TmpRepoPath |
|
|
|
|
|
|
|
|
|
// tree, err := exec.Command("/usr/bin/tree", git.TmpRepoPath).Output()
|
|
|
|
|
// check(err)
|
|
|
|
|
// fmt.Println(string(tree))
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hugoContext(hugo, git.RepoPath) |
|
|
|
|
|
|
|
|
|
logs := hugoRender(hugo, hook.Offline) |
|
|
|
|
// fmt.Println(logs)
|
|
|
|
|
logLines += fmt.Sprintf(logs) |
|
|
|
|
if git.IsBare { |
|
|
|
|
cleanUpPublicHTML(hugo, hook) |
|
|
|
|
copyToPublicHTML(hugo, hook) |
|
|
|
|
|
|
|
|
|
logLines += fmt.Sprintln("~~~~~~~~~~~~~~~~~~~~~~~~~~~") |
|
|
|
|
if hook.Publish { |
|
|
|
|
// fmt.Println("Web site:", filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName))
|
|
|
|
|
logLines += fmt.Sprintf("Web site: %s\n", filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName)) |
|
|
|
|
logLines += fmt.Sprintf("Web site path:\n%s", filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName)) |
|
|
|
|
} else { |
|
|
|
|
// fmt.Println("Web site:", filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview"))
|
|
|
|
|
logLines += fmt.Sprintf("Web site: %s\n", filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview")) |
|
|
|
|
logLines += fmt.Sprintf("Web site path:\n%s", filepath.Join(hook.PublicHTMLPath, hugo.PublicHTMLName, "_preview")) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// fmt.Println("Web site:", hugo.DestinationDir)
|
|
|
|
|
logLines += fmt.Sprintf("Web site: %s\n", hugo.DestinationDir) |
|
|
|
|
logLines += fmt.Sprintf("Web site path:\n%s", hugo.DestinationDir) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
durationMillseconds := int64(time.Since(startTime) / time.Millisecond) |
|
|
|
|
logLines = logLines + fmt.Sprintf("Total processing time: %d ms\n\nGit hook version: %s\n~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n", durationMillseconds, version) |
|
|
|
|
logLines = logLines + fmt.Sprintf("\n~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\nTotal githook time: %d ms\n~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n", durationMillseconds) |
|
|
|
|
logLines = logLines + startTime.Format(time.RFC822) + "\n~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~\n" |
|
|
|
|
|
|
|
|
|
logLines = logLines + "\n####################################\n" |
|
|
|
|
logLines = logLines + fmt.Sprintf("%#v", hugo) |
|
|
|
|
logLines = logLines + fmt.Sprintf("%#v", hook) |
|
|
|
|
|
|
|
|
|
writeLastCommitLog(logLines, git.IsBare, hugo, hook) |
|
|
|
|
fmt.Println(logLines) |
|
|
|
|
} |
|
|
|
|