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 + } +}