Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(242)

Side by Side Diff: misc/git/pre-commit

Issue 6843044: code review 6843044: misc/git: add gofmt git pre-commit hook (Closed)
Patch Set: diff -r cbb5a28097e9 https://code.google.com/p/go Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b