From d8181277e677a206f57e4dc609101ff1fb516e82 Mon Sep 17 00:00:00 2001 From: Martin Thielecke Date: Fri, 31 Jul 2015 23:58:20 +0000 Subject: [PATCH] [gotest] new hook for go test and added binary to gitignore --- .gitignore | 1 + githook-gotest/hook.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 githook-gotest/hook.go diff --git a/.gitignore b/.gitignore index f2b86c8..293164e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ githook-gofmt/githook-gofmt githook-gobuild/githook-gobuild +githook-gotest/githook-gotest diff --git a/githook-gotest/hook.go b/githook-gotest/hook.go new file mode 100644 index 0000000..99c683e --- /dev/null +++ b/githook-gotest/hook.go @@ -0,0 +1,25 @@ +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", "test", "-test.short", "./...") + if status != 0 { + fmt.Fprint(os.Stderr, "Test failed, please commit only stuff that works.\n") + os.Exit(1) + return + } +}