]> git.xonotic.org Git - xonotic/xonotic.git/blob - check-gitattributes.sh
another chdir
[xonotic/xonotic.git] / check-gitattributes.sh
1 #!/bin/bash
2
3 exec 3<&0
4
5 ISANYTHING=" -crlf"
6 ISBINARY=" -crlf -diff"
7 ISTEXT=" crlf=input"
8
9 LF="
10 "
11 eol=`cat .gitattributes`
12 find . -name .git -prune -o \( -type f -print \) | {
13         unseen=`echo "$eol" | cut -d ' ' -f 1 | grep .`
14         neweol=
15         while IFS= read -r LINE; do
16                 nam=${LINE##*/}
17                 case "$nam" in
18                         *.*)
19                                 nam=*.${nam##*.}
20                                 ;;
21                 esac
22                 t=`file -b --mime-type "$LINE"`
23                 case "$t" in
24                         application/x-symlink)
25                                 continue
26                                 ;;
27                         text/*|application/xml|application/x-ruby)
28                                 t=true
29                                 ;;
30                         *)
31                                 t=false
32                                 ;;
33                 esac
34                 unseen=`{ echo "$nam"; echo "$nam"; echo "$unseen"; } | sort | uniq -u`
35                 case "$LF$eol$LF$neweol$LF" in
36                         *$LF$nam$ISANYTHING$LF*)
37                                 # ignore and treat as binary
38                                 ;;
39                         *$LF$nam$ISBINARY$LF*)
40                                 # should be binary
41                                 if $t; then
42                                         echo "WARNING: file $LINE is text, should be binary"
43                                 fi
44                                 ;;
45                         *$LF$nam$ISTEXT$LF*)
46                                 # should be text
47                                 if ! $t; then
48                                         echo "WARNING: file $LINE is binary, should be text"
49                                 fi
50                                 ;;
51                         *)
52                                 # unknown
53                                 if $t; then
54                                         echo "NOTE: added new type TEXT for $LINE"
55                                         neweol="$neweol$LF$nam$ISTEXT"
56                                 else
57                                         echo "NOTE: added new type BINARY for $LINE"
58                                         neweol="$neweol$LF$nam$ISBINARY"
59                                 fi
60                                 ;;
61                 esac
62         done
63         echo "$neweol"
64         echo "not seen: $unseen"
65 }