File tree 2 files changed +57
-0
lines changed
2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ dist : bionic
2
+
3
+ stages :
4
+ - build
5
+
6
+ matrix :
7
+ include :
8
+ - name : Static checks (format.sh)
9
+ stage : build
10
+ os : linux
11
+ addons :
12
+ apt :
13
+ packages :
14
+ - dos2unix
15
+ - recode
16
+
17
+ script :
18
+ - bash ./format.sh
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Loops through all text files tracked by Git.
4
+ git grep -zIl ' ' |
5
+ while IFS= read -rd ' ' f; do
6
+ # Exclude csproj and hdr files.
7
+ if [[ $f == * " csproj" ]]; then
8
+ continue
9
+ elif [[ $f == * " hdr" ]]; then
10
+ continue
11
+ fi
12
+ # Ensures that files are UTF-8 formatted.
13
+ recode UTF-8 $f 2> /dev/null
14
+ # Ensures that files have LF line endings.
15
+ dos2unix $f 2> /dev/null
16
+ # Ensures that files do not contain a BOM.
17
+ sed -i ' 1s/^\xEF\xBB\xBF//' " $f "
18
+ # Ensures that files end with newline characters.
19
+ tail -c1 < " $f " | read -r _ || echo >> " $f " ;
20
+ done
21
+
22
+ git diff > patch.patch
23
+ FILESIZE=$( stat -c%s patch.patch)
24
+ MAXSIZE=5
25
+
26
+ # If no patch has been generated all is OK, clean up, and exit.
27
+ if (( FILESIZE < MAXSIZE )) ; then
28
+ printf " Files in this commit comply with the formatting rules.\n"
29
+ rm -f patch.patch
30
+ exit 0
31
+ fi
32
+
33
+ # A patch has been created, notify the user, clean up, and exit.
34
+ printf " \n*** The following differences were found between the code "
35
+ printf " and the formatting rules:\n\n"
36
+ cat patch.patch
37
+ printf " \n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
38
+ rm -f patch.patch
39
+ exit 1
You can’t perform that action at this time.
0 commit comments