From bc9051fd1a17e793647cf309c973a7feefebd98f Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Tue, 2 Nov 2021 16:10:57 -0300 Subject: down to the main package it seems --- .githooks/pre-commit | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to '.githooks/pre-commit') diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 7fda0a3..9e91920 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,14 +1,22 @@ #!/bin/sh -# This hook formats every Go file with `go fmt` before committing them. -# It helps to enforce the Go style guide for those who forget to format their code properly. +# This hook formats every Go file before committing them. +# It helps to enforce a consistent style guide for those who forget to format their code properly. STAGED="$(git diff --cached --name-only -- '*.go')" + if [ -n "$STAGED" ]; then for file in $STAGED; do + if [ ! -e "$file" ]; then + # file doesn't exist, skip + continue + fi + + # format the file go fmt "$file" # run goimports if it's there + # it organizes imports if command -v goimports >/dev/null 2>&1; then goimports -w "$file" fi -- cgit v1.2.3