Debian Codegraph @

dev/lint-commits.sh

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env bash
2
3 # A script to check prettyness for a range of commits
4 set -e
5
6 CALLNAME="$0"
7
8 function usage
9 {
10 >&2 echo "usage: $CALLNAME <commit> <commit>"
11 >&2 echo "The order of commits is as given to 'git diff'"
12 }
13
14 if [ "$#" != 2 ];
15 then
16 usage
17 exit 1
18 fi
19
20 REDBOLD="\033[31;1m"
21 RESET="\033[0m"
22
23 function redprint
24 {
25 if true || [ "$COQ_CI_COLOR" ]; then
26 printf "$REDBOLD%s$RESET\n" "$1"
27 else
28 printf '%s\n' "$1"
29 fi
30 }
31
32 BASE_COMMIT="$1"
33 HEAD_COMMIT="$2"
34
35 tmp=$(mktemp -d)
36 git worktree add "$tmp" "$HEAD_COMMIT"
37 pushd "$tmp"
38
39 bad_ws=()
40 bad_compile=()
41 while IFS= read -r commit; do
42 echo Checking "$commit"
43 git checkout "$commit"
44
45 # git diff --check
46 # uses .gitattributes to know what to check
47 if ! git diff --check "${commit}^" "$commit";
48 then bad_ws+=("$commit")
49 fi
50
51 if ! make check
52 then bad_compile+=("$commit")
53 fi
54 done < <(git rev-list "$HEAD_COMMIT" --not "$BASE_COMMIT" --)
55
56 popd
57 git worktree remove "$tmp"
58
59 # report errors
60
61 CODE=0
62
63 if [ "${#bad_ws[@]}" != 0 ]
64 then
65 >&2 redprint "Whitespace errors!"
66 >&2 echo "In commits ${bad_ws[*]}"
67 >&2 echo "If you use emacs, you can prevent this kind of error from reoccurring by installing ws-butler and enabling ws-butler-convert-leading-tabs-or-spaces."
68 >&2 echo
69 CODE=1
70 fi
71
72 if [ "${#bad_compile[@]}" != 0 ]
73 then
74 >&2 redprint "Compilation errors!"
75 >&2 echo "In commits ${bad_compile[*]}"
76 >&2 echo
77 CODE=1
78 fi
79
80 exit $CODE