devcam: run git pre-commit hook as a test.

Additional check to prevent b bad imports and un-go-fmt'd code
from sneaking in.
If users don't run tests, it will break the builder.

Change-Id: I95c74724aac68d915aa5195b6d8fcb78f92349e0
This commit is contained in:
Bill Thiede 2014-10-01 22:03:53 -07:00
parent 0aa0b18e5f
commit af19bf089c
2 changed files with 24 additions and 5 deletions

View File

@ -31,9 +31,10 @@ import (
type testCmd struct {
// start of flag vars
verbose bool
short bool
run string
verbose bool
precommit bool
short bool
run string
// end of flag vars
// buildGoPath becomes our child "go" processes' GOPATH environment variable
@ -44,6 +45,7 @@ func init() {
cmdmain.RegisterCommand("test", func(flags *flag.FlagSet) cmdmain.CommandRunner {
cmd := new(testCmd)
flags.BoolVar(&cmd.short, "short", false, "Use '-short' with go test.")
flags.BoolVar(&cmd.precommit, "precommit", true, "Run misc/pre-commit.githook as part of tests.")
flags.BoolVar(&cmd.verbose, "v", false, "Use '-v' (for verbose) with go test.")
flags.StringVar(&cmd.run, "run", "", "Use '-run' with go test.")
return cmd
@ -59,6 +61,11 @@ func (c *testCmd) Describe() string {
}
func (c *testCmd) RunCommand(args []string) error {
if c.precommit {
if err := c.runPrecommitHook(); err != nil {
return err
}
}
if err := c.syncSrc(); err != nil {
return err
}
@ -148,3 +155,12 @@ func (c *testCmd) runTests(args []string) error {
env.Set("SKIP_DEP_TESTS", "1")
return runExec("go", targs, env)
}
func (c *testCmd) runPrecommitHook() error {
out, err := exec.Command("./misc/pre-commit.githook", "test").CombinedOutput()
if err != nil {
fmt.Println(string(out))
}
return err
}

View File

@ -1,5 +1,6 @@
#!/usr/bin/env sh
mode=${1:-"precommit"}
exitstatus=0
#third_party imports.
@ -13,7 +14,7 @@ then
do
echo $r
done
echo "The above need their imports to be fixed. Use rewrite-imports.sh -w"
echo "The above need their imports to be fixed. Use third_party/rewrite-imports.sh -w"
fi
#gofmt and trailing space errors
@ -52,7 +53,9 @@ then
then
echo "gofmt -w $needFmt"
fi
echo "You can override this check with 'git commit --no-verify'"
if [ "$mode" != "test" ]; then
echo "You can override this check with 'git commit --no-verify'"
fi
fi
exit $exitstatus