| 1 | #!/usr/bin/env sh |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
| 5 | # DESCR: Run gofmt on util/intelp2m |
| 6 | |
| 7 | LINTDIR="$( |
| 8 | cd -- "$(dirname "$0")" > /dev/null 2>&1 || return |
| 9 | pwd -P |
| 10 | )" |
| 11 | |
| 12 | # shellcheck source=helper_functions.sh |
| 13 | . "${LINTDIR}/helper_functions.sh" |
| 14 | |
| 15 | # Until we require this by default, we need a list of opted-in directories |
| 16 | # If the script isn't looking at a git repository, just exit |
| 17 | if [ "${IN_GIT_TREE}" -eq 0 ]; then |
| 18 | exit 0 |
| 19 | fi |
| 20 | |
| 21 | files_to_check=$(${GIT} log HEAD~..HEAD --format= --name-only util/intelp2m | grep "\.go$") |
| 22 | |
| 23 | # nothing to do |
| 24 | if [ -z "$files_to_check" ]; then |
| 25 | exit 0 |
| 26 | fi |
| 27 | |
| 28 | diff_files=$(gofmt -l $files_to_check) |
| 29 | if [ "$diff_files" != "" ]; then |
| 30 | echo "Coding style mismatch. Run \"gofmt -w $files_to_check\" before pushing changes" |
| 31 | exit 1 |
| 32 | fi |
| 33 | exit 0 |