forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreformat.sh
executable file
·71 lines (58 loc) · 1.27 KB
/
reformat.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
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
set -eu
if ! (cmake-format --version >/dev/null); then
echo "cmake-format not available. Install it with 'pip install cmake-format'"
exit 1
fi
# GNU prefix command for mac os support (gsed)
GP=
# shellcheck disable=SC2039,SC3028
case "${OSTYPE:-}" in
darwin*)
GP=g
;;
esac
# determine changed files
MODIFIED=$(git status --porcelain| ${GP}sed -ne "s/^ *[MA] *//p" | sort -u)
if [ -z "$MODIFIED" ]; then
echo "nothing was modified"
exit 0
fi
FORMAT_FIX_DIFF=format_fix.diff
rm -f "$FORMAT_FIX_DIFF"
touch "$FORMAT_FIX_DIFF"
for f in $MODIFIED; do
case "$f" in
*CMakeLists.txt)
;;
*gdal.cmake)
;;
*cmake/helpers/CheckDependentLibraries.cmake)
;;
*)
continue
;;
esac
# Disable cmake-format (https://github.com/OSGeo/gdal/pull/5326#issuecomment-1042617407)
# m=$f.prepare
# cp "$f" "$m"
# cmake-format -i "$f"
# diff -u "$m" "$f" >> "$FORMAT_FIX_DIFF" || /bin/true
# rm -f "$m"
done
ret_code=0
if [ -s "$FORMAT_FIX_DIFF" ]; then
ret_code=1
# review changes
if tty -s; then
if ! (colordiff --version >/dev/null); then
cat "$FORMAT_FIX_DIFF"
else
colordiff < "$FORMAT_FIX_DIFF" | less -r
fi
else
cat "$FORMAT_FIX_DIFF"
fi
fi
rm -f "$FORMAT_FIX_DIFF"
exit $ret_code