From 33fdadb05fbc185f4c0258eb8072ee8813ffe614 Mon Sep 17 00:00:00 2001 From: Martin Thielecke Date: Fri, 31 Jul 2015 23:53:25 +0000 Subject: [PATCH] [gobuild] initial hook to check the build --- githook-gobuild/hook.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 githook-gobuild/hook.go diff --git a/githook-gobuild/hook.go b/githook-gobuild/hook.go new file mode 100644 index 0000000..2545e7d --- /dev/null +++ b/githook-gobuild/hook.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "os" + + "github.com/mthie/git-gohooks/general" +) + +func main() { + files := general.GetChangedGoFiles() + if files == nil { + 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", ".", "./...") +}