From 4a184c84d5e63d418a4e3b738ffea6c1f9750158 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 16 Oct 2012 16:31:23 +0200 Subject: [PATCH] pre-commit git hook: -gofmt -trailing space check Change-Id: Icd63483b1873b21cd5ff6f00fff4b191095942ad --- misc/pre-commit.githook | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 misc/pre-commit.githook diff --git a/misc/pre-commit.githook b/misc/pre-commit.githook new file mode 100755 index 000000000..f9fd2d36b --- /dev/null +++ b/misc/pre-commit.githook @@ -0,0 +1,29 @@ +#!/usr/bin/env sh + +exitstatus=0 +committed=`git diff-index --cached --name-only HEAD` +for c in $committed +do + gofile=`echo $c | grep -E '.*\.go$'` + if [ -n "$gofile" ] + then + fmtdiff=`gofmt -d $c 2>&1` + if [ -n "$fmtdiff" ] + then + echo "gofmt needed on "$c + exitstatus=1 + fi + trailspace=`git diff-index --cached --check HEAD $c | grep 'trailing whitespace'` + if [ -n "$trailspace" ] + then + echo $trailspace + exitstatus=1 + fi + fi +done +if [ "$exitstatus" -ne 0 ] +then + echo "You can override this check with 'git commit --no-verify'" +fi + +exit $exitstatus