Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #!/bin/sh | |
2 # Copyright 2012 The Go Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style | |
4 # license that can be found in the LICENSE file. | |
5 | |
6 # git gofmt pre-commit hook | |
7 # | |
8 # To use, store as .git/hooks/pre-commit inside your repository and make sure | |
9 # it has execute permissions. | |
minux1
2012/11/14 10:34:09
do you want to document that it doesn't handle spa
adg
2012/11/14 10:39:54
Documented.
| |
10 | |
11 gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') | |
12 [ -z "$gofiles" ] && exit 0 | |
13 | |
14 unformatted=$(gofmt -l $gofiles) | |
minux1
2012/11/14 10:34:09
do you want to ignore messages on stderr?
gofmt wi
adg
2012/11/14 10:39:54
I'd prefer not to hide the messages. At least then
| |
15 [ -z "$unformatted" ] && exit 0 | |
16 | |
17 # Some files are not gofmt'd. Print message and fail. | |
18 | |
19 echo >&2 "Go files must be formatted with gofmt. Please run:\n" | |
minux1
2012/11/14 10:34:09
echo with \n?
adg
2012/11/14 10:39:54
Done.
| |
20 printf >&2 " gofmt -w" | |
21 echo "$unformatted" | while read fn; do | |
22 echo >&2 " \\" | |
23 printf >&2 " %s/%s" "${PWD}" "${fn}" | |
minux1
2012/11/14 10:34:09
why {}? "$PWD" "$fn" is ok.
adg
2012/11/14 10:39:54
Done.
| |
24 done | |
25 echo >&2 | |
26 | |
27 exit 1 | |
OLD | NEW |