Created
July 12, 2015 04:47
Revisions
-
AustinDizzy created this gist
Jul 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/bin/sh # Modified 2015, Austin Dizzy # Copyright 2012 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. # git gofmt pre-commit hook # # To use, store as .git/hooks/pre-commit inside your repository and make sure # it has execute permissions. # # This script does not handle file names that contain spaces. gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') [ -z "$gofiles" ] && exit 0 unformatted=$(gofmt -l $gofiles) [ -z "$unformatted" ] && exit 0 # Some files are not gofmt'd. Print message and fail. echo >&2 "The following Go files are not gofmt'd:" for fn in $unformatted; do echo >&2 " [*] $fn" done exec < /dev/tty read -p "Would you like to gofmt them? (Y/n) " yn if [ "$yn" = "" ]; then yn='Y' fi case $yn in [Yy]) for fn in $unformatted; do eval "gofmt -w $PWD/$fn" eval "git add $PWD/$fn" done ;; [Nn]) exit 0 ;; * ) echo "Please answer y or n for yes or no.";; esac exec <&- exit 0