-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest-hook.sh
executable file
·76 lines (61 loc) · 1.59 KB
/
test-hook.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
72
73
74
75
#!/bin/sh
#
# Licensed under 3-Clause BSD, see License.txt
#
# test suite for hook
cp pre-commit .git/hooks
chmod a+x .git/hooks
git config --replace-all hooks.enforcecompatiblefilenames true
commit=$(git rev-parse HEAD)
counter=0
checkname ()
{
filename="$1"
counter=$(expr $counter \+ 1)
mkdir -p "$(dirname "$filename")" &&
touch "$filename" &&
git add "$filename" &&
GIT_TRACE=1 git commit -m "my message"
ret=$?
git reset --hard $commit > /dev/null
expected_exit_code=${2:-1}
if test $ret -eq $expected_exit_code
then
echo "Test $counter passed"
else
echo "Failed"
exit 1
fi
}
echo "non printable characters"
checkname "a\t.pdf"
checkname "b\n.pdf"
echo "###illegal chars###"
checkname "a<.txt"
checkname "a>.txt"
checkname "a:.txt"
checkname "a\".txt"
checkname "a\\.txt"
checkname "a|.txt"
checkname "a?.txt"
checkname "a*.txt"
echo "###reserved names###"
checkname "CON.txt"
checkname "AUX.txt"
checkname "LPT1.txt"
checkname "COM1"
checkname "NUL"
checkname "sub/folder/PRN"
checkname "comic-con.txt" 0
echo "###no trailing period or space###"
checkname " "
checkname "a.txt."
checkname "b.txt. "
checkname "c.txt ."
echo "###filename all periods###"
checkname "..."
echo "###absolute path too long###"
path="1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890"
mkdir -p $path
validfile="a.txt"
checkname "$path/$validfile"