Skip to content

Instantly share code, notes, and snippets.

@kdridi
Created October 5, 2017 22:55
Show Gist options
  • Save kdridi/518bbd1334030a6ac8c2b29c909bb5c2 to your computer and use it in GitHub Desktop.
Save kdridi/518bbd1334030a6ac8c2b29c909bb5c2 to your computer and use it in GitHub Desktop.
.git/hooks/pre-commit
#!/usr/bin/env bash
################################################################################
echo -n "Object files: "
################################################################################
if test -f *.o; then
echo "KO"
exit 84
else
echo "OK"
fi
################################################################################
echo -n "Compilation: "
################################################################################
gcc -W -Wall -Wextra -Werror -c *.c
if [[ $? == 0 ]]; then
echo "OK"
else
echo "KO"
exit 84
fi
################################################################################
echo -n "Function main doesn't exist: "
################################################################################
if [[ 0 -eq $(nm *.o | egrep ' T _main$' | wc -l) ]]; then
echo "OK"
else
echo "KO"
rm -rf *.o
exit 84
fi
################################################################################
echo -n "Function my_putchar doesn't exist: "
################################################################################
if [[ 0 -eq $(nm *.o | egrep ' T _my_putchar$' | wc -l) ]]; then
echo "OK"
else
echo "KO"
rm -rf *.o
exit 84
fi
rm -rf *.o
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment