Skip to content

Instantly share code, notes, and snippets.

@nl5887
Last active May 19, 2021 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nl5887/dca1b363b8adc39984839de2808ed322 to your computer and use it in GitHub Desktop.
Save nl5887/dca1b363b8adc39984839de2808ed322 to your computer and use it in GitHub Desktop.
Git pre commit hook

Copy the pre-commit file in .git/hooks/pre-commit and you'll never commit a non-working Go build again.

#!/bin/bash
set -e
DEST=$(mktemp -d)
SRC=$(pwd)
pushd .
cd $DEST; git clone --depth=1 $SRC/.git . >/dev/null 2>&1
cd $SRC; git diff -P --cached | patch -p1 -d $DEST >/dev/null
cd $DEST; go build .
cd $DEST; go test ./...
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment