Skip to content

Commit

Permalink
Pre-commit should run go fmt on go files
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Jan 23, 2023
1 parent 7a03061 commit 4867c42
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hooks/common/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,17 @@ if ! get_config_bool gitflow.branch.allow-conflict-commit; then
[[ ${#files_to_merge[@]} > 0 ]] && die "Resolve these merges before committing! ${files_to_merge[@]}"
fi

STAGED_GO_FILES=$(git diff --cached --name-only | grep "\.go$")
[[ -z $STAGED_GO_FILES ]] && exit 0

GOFMT=$(command -v gofmt)
if (( $? )); then
GOFMT=$GOROOT/bin/gofmt
[[ ! -e $GOFMT ]] && die "The gofmt tool is missing, aborting"
fi

for file in $STAGED_GO_FILES ; do
$GOFMT -w $file
done

exit 0

0 comments on commit 4867c42

Please sign in to comment.