-
Notifications
You must be signed in to change notification settings - Fork 20
/
step-097.sh
55 lines (44 loc) · 1.43 KB
/
step-097.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
#!/bin/sh
# Test:
# Direct template execution: list of staged files (hook types)
MANAGED_HOOK_NAMES="
applypatch-msg pre-applypatch post-applypatch
pre-commit pre-merge-commit prepare-commit-msg commit-msg post-commit
pre-rebase post-checkout post-merge pre-push
pre-receive update post-receive post-update reference-transaction
push-to-checkout pre-auto-gc post-rewrite sendemail-validate
post-index-change
"
SINGLE="--single"
if echo "$EXTRA_INSTALL_ARGS" | grep -q "use-core-hookspath"; then
# Do not use single install with core.hooksPath
SINGLE=""
fi
# shellcheck disable=SC2086
mkdir -p /tmp/test097/.git/hooks &&
cd /tmp/test097 &&
git init &&
sh /var/lib/githooks/install.sh $SINGLE &&
git config githooks.autoupdate.enabled false ||
exit 1
for HOOK_TYPE in ${MANAGED_HOOK_NAMES}; do
mkdir -p ".githooks/${HOOK_TYPE}" || exit 1
cat <<EOF >".githooks/${HOOK_TYPE}/${HOOK_TYPE}" || exit 1
printf "hook=\$(basename \$0) -- " >> /tmp/test097.out
for STAGED in \${STAGED_FILES}; do
echo "\${STAGED}" >> /tmp/test097.out
done
EOF
done
echo "test" >testing.txt
git add testing.txt
ACCEPT_CHANGES=A git commit -m 'testing hooks'
cat /tmp/test097.out
if [ "$(grep -c "testing.txt" /tmp/test097.out)" != "3" ]; then
echo "! Unexpected number of output rows"
exit 1
fi
if [ "$(grep -c "hook=" /tmp/test097.out)" != "4" ]; then
echo "! Unexpected number of hooks run"
exit 1
fi