-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·63 lines (49 loc) · 1.68 KB
/
entrypoint.sh
File metadata and controls
executable file
·63 lines (49 loc) · 1.68 KB
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
#!/bin/bash
printf "check EOL in: $1\n"
BOLD_RED='\033[1;31m'
BOLD_GREEN='\033[1;32m'
BOLD_YELLOW='\033[1;33m'
BOLD_CYAN='\033[1;36m'
NC='\033[0m'
rErrors=()
rInfos=()
files=$(git ls-files --eol $1)
# echo "$files"
while IFS= read -r line; do
file_name=$(echo $line |awk '{ print $NF }')
attribute=$(echo $line |awk 'match($0, / attr\/(text|-text) /) { print substr( $0, RSTART+6, RLENGTH-7 )}')
working_tree=$(echo $line |awk 'match($0, / w\/(lf|crlf|mixed|none) /) { print substr( $0, RSTART+3, RLENGTH-4 )}')
expected=$(echo $line |awk 'match($0, / eol=(lf|crlf|mixed|none) /) { print substr( $0, RSTART+5, RLENGTH-6 )}')
# echo "$file_name -- ##$attribute##"
if [[ "$attribute" == "text" ]]
then
if [[ -z "$expected" ]]
then
msg=$( printf "${BOLD_YELLOW}No EOL rule defined for %s${NC}\n" $file_name)
rInfos+=("$msg")
else
if [[ "$working_tree" != "$expected" && "$working_tree" != "none" ]]
then
msg=$( printf "Found file ${BOLD_RED}%s${NC} with ${BOLD_CYAN}%s${NC} endings but expected ${BOLD_YELLOW}%s.${NC}\n" $file_name $working_tree $expected)
rErrors+=("$msg")
fi
fi
fi
done <<< "$files"
for value in "${rInfos[@]}"
do
echo $value
done
if [ "${#rErrors[@]}" -eq 0 ]
then
printf "${BOLD_GREEN}No files with EOL errors found.${NC}\n"
exit 0
else
for value in "${rErrors[@]}"
do
echo $value
done
printf "${BOLD_YELLOW} %s files with EOL warnings found.${NC}\n" ${#rInfos[@]}
printf "${BOLD_RED} %s files with EOL errors found.${NC}\n" ${#rErrors[@]}
exit ${#rErrors[@]}
fi