diff options
author | KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> | 2021-11-02 16:10:57 -0300 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | bc9051fd1a17e793647cf309c973a7feefebd98f (patch) | |
tree | bf16a2176e9129c3921ef6743a6c22781e744064 /.githooks | |
parent | d80afd8a49f552c5dc51d8346d40809298fef11f (diff) |
down to the main package it seems
Diffstat (limited to '.githooks')
-rwxr-xr-x | .githooks/pre-commit | 12 |
1 files changed, 10 insertions, 2 deletions
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 |