diff --git a/dev/devcam/test.go b/dev/devcam/test.go index 7523e0afa..4b134a40e 100644 --- a/dev/devcam/test.go +++ b/dev/devcam/test.go @@ -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 + +} diff --git a/misc/pre-commit.githook b/misc/pre-commit.githook index 1bb12ad0e..f6f9c0e24 100755 --- a/misc/pre-commit.githook +++ b/misc/pre-commit.githook @@ -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