Skip to content

Instantly share code, notes, and snippets.

@MacoTasu MacoTasu/pre-commit
Last active Jun 28, 2019

Embed
What would you like to do?
commitするときに、差分のあったファイルのみgo fmtを実行して、変なフォーマットがないかチェックするためのshellscript
#!/bin/sh
before_diff_bytes=`git diff | wc -c`
diff_files=(`git diff --name-only HEAD ./`)
for diff_file in "${diff_files[@]}"
do
if [[ $diff_file =~ \.go$ ]]; then
gofmt -w $diff_file
fi
done
after_diff_bytes=`git diff | wc -c`
diff_bytes=`expr $after_diff_bytes \- $before_diff_bytes`
if [[ $diff_bytes > 0 ]] ; then
echo "\033[0;31m Check golang code format! \033[0;39m"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.