git-gohooks/githook-gobuild/hook.go
2022-05-20 21:42:53 +02:00

27 lines
446 B
Go

package main
import (
"fmt"
"os"
"go.mthie.com/git-gohooks/general"
)
func main() {
files := general.GetChangedGoFiles()
if len(files) == 0 {
os.Exit(0)
return
}
os.Chdir(general.GetGitRoot())
_, status := general.RunCommand("go", "build", ".", "./...")
if status != 0 {
fmt.Fprint(os.Stderr, "Build failed, please commit only stuff that builds.\n")
os.Exit(1)
return
}
general.RunCommand("go", "clean", ".", "./...")
}