aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts/pre-commit
blob: b75ea9fc3db36ac9b89b560e9505e3d513f506a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

if ! command -v git-clang-format &> /dev/null; then
	echo "Please make sure git-clang-format is available." >&2
	exit 1
fi

output="$( git clang-format --style file --diff )"

ok1='no modified files to format'
ok2='clang-format did not modify any files'

if [ "$output" != "$ok1" ] && [ "$output" != "$ok2" ]; then
	echo "$output"
	echo
	echo 'clang-format required some formatting fixes.'
	echo 'Please stage your changes, run `git clang-format`, review the formatting fixes, and commit.'
	exit 1
fi