I am writing a post-receive script in GIT.
I attach a minimal version of it, which also fails:
generate_email()
{
for user in $(git config --get-all notifications.users); do
unset files_to_notify
for filter in $(git config --get-all notifications.$user); do
files_to_notify=" $files_to_notify $(git diff-tree --no-commit-id \
--name-only -r $newrev | grep $filter) "
done
files_to_notify=( $files_to_notify )
if [ -n "$files_to_notify" ]; then
echo ${files_to_notify[*]}
fi
done
}
while read oldrev newrev refname
do
generate_email $oldrev $newrev $refname
done
When I’m trying to push to git server in invoke this script, I get the following message:
remote: hooks/post-receive: 10: hooks/post-receive: Syntax error: “(” unexpected (expecting “done”)
When I try to run it in command-line, the script works correctly without this message.
Any Ideas?
Thanks,
Elyashiv
Two possibilities:
Add
#!/usr/bin/env bashto the top of the script to ensure the script is run bybashand notsh, since you use an array, abashextension.Stop using the array, since you don’t use it in any way that couldn’t easily be replaced with a simple space-delimited string. That’s how you are building the array in the first place.