Fix golint pre commit hook for non-interactive shell.

When running the precommit commands from Eclipse, such a shell is used.
This commit is contained in:
Michael Berlin 2015-08-04 14:17:32 -07:00
Родитель 813e4f1de9
Коммит 90a372642c
1 изменённых файлов: 27 добавлений и 18 удалений

Просмотреть файл

@ -35,28 +35,37 @@ done
[ -z "$errors" ] && exit 0 [ -z "$errors" ] && exit 0
# git doesn't give us access to user input, so let's steal it. if [[ $- == *i* ]]; then
exec < /dev/tty # interactive shell. Prompt the user.
# git doesn't give us access to user input, so let's steal it.
exec < /dev/tty
echo echo
echo "Lint suggestions were found. They're not enforced, but we're pausing" echo "Lint suggestions were found. They're not enforced, but we're pausing"
echo "to let you know before they get clobbered in the scrollback buffer." echo "to let you know before they get clobbered in the scrollback buffer."
echo echo
read -r -p 'Press enter to cancel, "s" to step through the warnings or type "ack" to continue: ' read -r -p 'Press enter to cancel, "s" to step through the warnings or type "ack" to continue: '
if [ "$REPLY" = "ack" ]; then if [ "$REPLY" = "ack" ]; then
exit 0 exit 0
fi fi
if [ "$REPLY" = "s" ]; then if [ "$REPLY" = "s" ]; then
first_file="true" first_file="true"
for gofile in "${gofiles_with_warnings[@]}"
do
echo
if [ "$first_file" != "true" ]; then
echo "Press enter to show the warnings for the next file."
read
fi
golint $gofile
first_file="false"
done
fi
else
# non-interactive shell (e.g. called from Eclipse). Just display the errors.
for gofile in "${gofiles_with_warnings[@]}" for gofile in "${gofiles_with_warnings[@]}"
do do
echo
if [ "$first_file" != "true" ]; then
echo "Press enter to show the warnings for the next file."
read
fi
golint $gofile golint $gofile
first_file="false"
done done
fi fi
exit 1 exit 1