Guest User

Untitled

a guest
Oct 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # --- Command line
  4. refname="$1"
  5. oldrev="$2"
  6. newrev="$3"
  7. branch=${refname#refs/heads/}
  8.  
  9. # Make a temp directory for writing the .jshintrc file
  10. TMP_DIR=`mktemp -d`
  11. EXIT_CODE=0
  12.  
  13. # If commit was on the master branch
  14. if [ "$branch" == "master" ]
  15. then
  16. # See if the git repo has a .jshintrc file
  17. JSHINTRC=`git ls-tree --full-tree --name-only -r HEAD -- | egrep .jshintrc`
  18.  
  19. JSHINT="jshint"
  20. if [ -n "$JSHINTRC" ]
  21. then
  22. # Create a path to a temp .jshintrc file
  23. JSHINTRC_FILE="$TMP_DIR/`basename \"$JSHINTRC\"`"
  24.  
  25. # Write the repo file to the temp location
  26. git cat-file blob HEAD:$JSHINTRC > $JSHINTRC_FILE
  27.  
  28. # Update the JSHint command to use the configuration file
  29. JSHINT="$JSHINT --config=$JSHINTRC_TMP_DIR/$JSHINTRC"
  30. fi
  31.  
  32. # Check all of the .js files that changed between oldrev and newrev
  33. for FILE in `git diff --name-only -r ${oldrev} ${newrev} -- | egrep *.js`; do
  34. # Get just the path of the file
  35. FILE_PATH=`dirname ${FILE}`
  36.  
  37. # Join that with the tmp directory; make if it does not exist
  38. FULL_PATH=${TMP_DIR}/${FILE_PATH}
  39. mkdir -p ${FULL_PATH}
  40.  
  41. # Write the file from Git
  42. git cat-file blob ${newrev}:${FILE} > "$TMP_DIR/$FILE"
  43.  
  44. # Run JSHint on the file and redirect the output back to Git
  45. ${JSHINT} ${TMP_DIR}/${FILE} >&2
  46.  
  47. # Capture the exit status of last command
  48. EXIT_CODE=$((${EXIT_CODE} + $?))
  49.  
  50. # If the EXIT_CODE is not 0 fail
  51. if [[ $EXIT_CODE -ne 0 ]]
  52. then
  53. rm -rf ${TMP_DIR}
  54. exit $EXIT_CODE
  55. fi
  56. done
  57.  
  58. # Clean-up the created files
  59. rm -rf ${TMP_DIR}
  60. fi
  61.  
  62. # Not updating master
  63. exit 0
Add Comment
Please, Sign In to add comment