-
Notifications
You must be signed in to change notification settings - Fork 6
/
check_format.sh
executable file
·61 lines (53 loc) · 1.33 KB
/
check_format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/bash
#
# This script returns 0 if the difference with REF_BRANCH has formatted according to STYLE
#
set -euo pipefail
function usage
{
echo "Usage: $0 [-h|--help]"
echo ""
echo "Checks the formatting of the current branch by comparing it to the reference one"
echo "Options:"
echo "-h|--help : print this help and exits"
}
function check_formatting
{
local readonly REF_BRANCH=$1
local readonly STYLE=$2
shift 2
local readonly FILE_TYPES="$@"
local OUTPUT=$(git diff -U0 --no-color ${REF_BRANCH} -- ${FILE_TYPES} | python2 $(which clang-format-diff) -p1 -style=${STYLE})
if [[ -z "${OUTPUT}" ]]; then
echo "Everything correctly formatted!"
exit 0
else
echo "Some files are not correclty formatted!"
echo "${OUTPUT}"
exit 1
fi
}
while getopts ":h:-help" option; do
case "${option}" in
h)
usage
exit 0
;;
-help)
usage
exit 0
;;
*)
usage
exit 255
;;
esac
done
if [[ $# -ne 0 ]]; then
usage
exit 255
fi
readonly REFERENCE_BRANCH="master"
readonly FILES_TYPES="main.cc eucclhyd_remap/*.cc eucclhyd_remap*.h"
readonly STYLE_EXPECTED="Google"
check_formatting $REFERENCE_BRANCH $STYLE_EXPECTED $FILES_TYPES