git-gohooks/githook-gobuild/hook.go
Ingo Oeser f1a92ba9fc Checking via len is more robust
because sometimes such APIs return nil slices, sometimes empty slices.
We want nothing to happen in both cases.
2015-08-22 23:52:09 +02:00

27 lines
450 B
Go

package main
import (
"fmt"
"os"
"github.com/mthie/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", ".", "./...")
}