Guest User

Untitled

a guest
Mar 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #!/usr/bin/env sh
  2. # pre-commit.sh
  3.  
  4. STASH_NAME="pre-commit-$(date +%s)"
  5. BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
  6. RED='\033[1;31m'
  7. GREEN='\033[1;32m'
  8. YELLOW='\033[1;33m'
  9. NC='\033[0m'
  10. BOLD='\033[1m'
  11.  
  12. # Check if commit is on a rebase, if not proceed as usual
  13. if [ $BRANCH_NAME != '(no branch)' ]
  14. then
  15. stash=0
  16. # Check to make sure commit isn't emtpy, exit with status 1 if it is
  17. if git diff-index --quiet HEAD --; then
  18. echo "${RED}You've tried to commit an empty commit${NC}"
  19. echo "\tMake sure to add your changes with 'git add'"
  20. exit 1
  21. else
  22. # Stash all changes in the working directory so we test only commit files
  23. if git stash save -u -k -q $STASH_NAME; then
  24. echo "${YELLOW}Stashed changes as:${NC} ${STASH_NAME}\n\n"
  25. stash=1
  26. fi
  27. fi
  28.  
  29. echo "${GREEN} Testing commit${NC}\n\n"
  30.  
  31. echo "${YELLOW}${BOLD}Cargo Test${NC}\n"
  32. cargo test --all &&
  33. cargo doc --no-deps
  34.  
  35. cargo_pass=$?
  36.  
  37. echo "\n\n${YELLOW}${BOLD}Godot Test${NC}\n"
  38.  
  39. cargo build --manifest-path ./test/Cargo.toml &&
  40. cp ./target/debug/libgdnative_test.so ./test/project/lib &&
  41. godot --path ./test/project
  42.  
  43. # Capture exit code from tests
  44. godot_pass=$?
  45.  
  46. # Revert stash if changes were stashed to restor working directory files
  47. if [ "$stash" -eq 1 ]
  48. then
  49. if git stash pop -q; then
  50. echo "\n\n${GREEN}Reverted stash command${NC}"
  51. else
  52. echo "\n\n${RED}Unable to revert stash command${NC}"
  53. fi
  54. fi
  55. # Inform user of build failure
  56. if [ "$cargo_pass" -ne "0" ]
  57. then
  58. echo "${RED}Build failed:${NC} if you still want to commit use ${BOLD}'--no-verify'${NC}"
  59. fi
  60.  
  61. # Exit with exit code from tests, so if they fail, prevent commit
  62. exit "$(($cargo_pass || $godot_pass))"
  63. else
  64. # Tests were skipped for rebase, inform user and exit zero
  65. echo "${YELLOW}Skipping tests on branchless commit${NC}"
  66. exit 0
  67. fi
Add Comment
Please, Sign In to add comment