hookGofmt runs a gofmt check on the local files matching the files in the git staging area. An error is returned if something went wrong or if some of the files need gofmting. In the latter case, the instruction is printed.
()
| 148 | // An error is returned if something went wrong or if some of the files need |
| 149 | // gofmting. In the latter case, the instruction is printed. |
| 150 | func (c *hookCmd) hookGofmt() error { |
| 151 | if os.Getenv("GIT_GOFMT_HOOK") == "off" { |
| 152 | printf("gofmt disabled by $GIT_GOFMT_HOOK=off\n") |
| 153 | return nil |
| 154 | } |
| 155 | |
| 156 | files, err := c.runGofmt() |
| 157 | if err != nil { |
| 158 | printf("gofmt hook reported errors:\n\t%v\n", strings.Replace(strings.TrimSpace(err.Error()), "\n", "\n\t", -1)) |
| 159 | return errors.New("gofmt errors") |
| 160 | } |
| 161 | if len(files) == 0 { |
| 162 | return nil |
| 163 | } |
| 164 | printf("You need to format with gofmt:\n\tgofmt -w %s\n", |
| 165 | strings.Join(files, " ")) |
| 166 | return errors.New("gofmt required") |
| 167 | } |
| 168 | |
| 169 | func (c *hookCmd) hookTrailingSpace() error { |
| 170 | // see 'pathspec' for the ':!' syntax to ignore a directory. |
no test coverage detected