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

This commit is contained in:
Mathieu Lonjaret 2014-10-27 21:44:54 +00:00 committed by Gerrit Code Review
commit 0ac70ad2a5
2 changed files with 24 additions and 5 deletions

View File

@ -32,6 +32,7 @@ import (
type testCmd struct {
// start of flag vars
verbose bool
precommit bool
short bool
run string
// end of flag vars
@ -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
if [ "$mode" != "test" ]; then
echo "You can override this check with 'git commit --no-verify'"
fi
fi
exit $exitstatus