pre-commit.sh 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. #
  3. #
  4. # Our "pre-commit" hook.
  5. # save current config
  6. echo "\n\nSaving current config\n\n"
  7. cp config.status tmp.status
  8. cp wolfssl/options.h tmp.options.h
  9. # stash modified files, if any, that are not part of this commit, don't test
  10. # them
  11. STASHED=0
  12. if ! git diff --quiet
  13. then
  14. STASHED=1
  15. echo "\n\nStashing modified files not part of commit\n\n"
  16. git stash -q --keep-index
  17. fi
  18. # do the commit tests
  19. echo "\n\nRunning commit tests...\n\n"
  20. ./commit-tests.sh
  21. RESULT=$?
  22. # restore modified files not part of this commit
  23. if test $STASHED -eq 1
  24. then
  25. echo "\n\nPopping stashed modified files not part of commit\n"
  26. git stash pop -q
  27. fi
  28. # restore current config
  29. echo "\nRestoring current config\n"
  30. mv tmp.status config.status
  31. # don't show output in case error from above
  32. ./config.status >/dev/null 2>&1
  33. mv tmp.options.h wolfssl/options.h
  34. make clean >/dev/null 2>&1
  35. make -j 8 >/dev/null 2>&1
  36. [ $RESULT -ne 0 ] && echo "\nOops, your commit failed\n" && exit 1
  37. echo "\nCommit tests passed!\n"
  38. exit 0