From c4789ccb2860831edb89d45a9da10a36572ac22c Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 2 Jan 2021 18:02:20 +0800 Subject: [PATCH 1/2] add a pre-commit hook that checks that tests are not focussed --- .githooks/README.md | 8 ++++++++ .githooks/pre-commit | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .githooks/README.md create mode 100755 .githooks/pre-commit diff --git a/.githooks/README.md b/.githooks/README.md new file mode 100644 index 000000000..e38700cf6 --- /dev/null +++ b/.githooks/README.md @@ -0,0 +1,8 @@ +# Git Hooks + +This directory contains useful Git hooks for working with quic-go. + +Install them by running +```bash +git config core.hooksPath .githooks +``` diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..a19cc2371 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,18 @@ +#!/bin/bash + +# Check that test files don't contain focussed test cases. +errored=false +for f in $(git diff --cached --name-only); do + if [[ $f != *_test.go ]]; then continue; fi + output=$(grep -n -e "FIt(" -e "FContext(" -e "FDescribe(" "$f") + if [ $? -eq 0 ]; then + echo "$f contains a focussed test:" + echo "$output" + echo "" + errored=true + fi +done + +if [ "$errored" = true ]; then + exit 1 +fi From 12571e3668c5f66cb8af3d5605eb45ecd1279b77 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 2 Jan 2021 18:02:59 +0800 Subject: [PATCH 2/2] add a pre-commit hook that check that files are properly gofumpt-ed --- .githooks/pre-commit | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index a19cc2371..4a9aedc1c 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -13,6 +13,14 @@ for f in $(git diff --cached --name-only); do fi done +# Check that all files are properly gofumpt-ed. +output=$(gofumpt -d $(git diff --cached --name-only)) +if [ -n "$output" ]; then + echo "Found files that are not properly gofumpt-ed." + echo "$output" + errored=true +fi + if [ "$errored" = true ]; then exit 1 fi