Skip to content

Commit 0f18c39

Browse files
fix: surrond source call with file existence check
1 parent 467b4b9 commit 0f18c39

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

.githooks/init_hooks.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ do
2020
git_hook_path="../.git/hooks/$hook"
2121

2222
web3swift_hook_comment="# web3swift git hook to perform actions like SwiftLint and codespell"
23-
web3swift_hook_path="source $(pwd)/${hook}"
23+
web3swift_hook_path="$(pwd)/${hook}"
24+
web3swift_hook_command="source $(pwd)/${hook}"
2425

2526
is_hook_linked=false
2627

2728
if test -f $git_hook_path; then
2829
last_line=$( tac ${git_hook_path} | grep -m 1 -E '[^[:space:]]' )
29-
if [ "$last_line" = "$web3swift_hook_path" ]; then
30+
if [ "$last_line" = "$web3swift_hook_command" ]; then
3031
is_hook_linked=true
3132
fi
3233
else
@@ -36,7 +37,13 @@ do
3637
fi
3738

3839
if [ "$is_hook_linked" = false ] ; then
39-
echo "$web3swift_hook_path" >> $git_hook_path
40+
cat << EOF >> $git_hook_path
41+
web3swift_hook_path=${web3swift_hook_path}
42+
43+
if test -f \$web3swift_hook_path; then
44+
${web3swift_hook_command}
45+
fi
46+
EOF
4047
echo "${hook} is linked successfully."
4148
else
4249
echo "${hook} is already linked."

0 commit comments

Comments
 (0)