Guest User

Untitled

a guest
Jun 21st, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # Copyright 2010 David M. Lee, II <leedm777@yahoo.com>
  5. #
  6. # This git update hook compares the author emails from commits with a
  7. # whitelist stored in ${GIT_DIR}/author-whitelist. If any commit has an
  8. # author that is not whitelisted, the offending author's email is displayed
  9. # then the update is rejected.
  10. #
  11.  
  12. if test -z ${GIT_DIR}; then
  13. cat <<EOF >&2
  14. Do not run directly. This is a git update hook.
  15. EOF
  16. exit 1
  17. fi
  18.  
  19. # Prints a list of all authors for the given revlist to stdout
  20. function git-authors
  21. {
  22. git rev-list --pretty=format:"%ae" "$1" | grep -v "^commit " | sort | uniq
  23. }
  24.  
  25. function commit-authors
  26. {
  27. if test "$1" -eq 0000000000000000000000000000000000000000; then
  28. # creating a new branch. Unfortunately, we don't know if we're
  29. # cloning an existing branch or not, so we'll have to check all
  30. # revisions. This went pretty quick on an Ubuntu 10.10 VM against
  31. # the Linux kernel repo (8601 authors, 221706 commits, < 7 seconds).
  32. # I doubt a performance optimization is necessary.
  33. git-authors $2
  34. else
  35. git-authors $1..$2
  36. fi
  37. }
  38.  
  39. # Some things to note when modifying this script
  40. # * the output from commit-authors can be pretty much anything. Just clone
  41. # the Linux kernel repo and look at the authors. Given that, you
  42. # _really_ have to be careful about shell injection.
  43. #
  44. # * the grep below will remove whitelisted authors from the list of
  45. # commit-authors. it will return 0 if there are non-whitelisted
  46. # commit-authors.
  47. #
  48. # * as a (pleasant) side effect, the list of non-whitelisted authors is
  49. # printed to stdout.
  50. #
  51. # * this is surpisingly fast; it took less than 100ms to compare 8601
  52. # commit-authors against a whitelist of 8601 authors.
  53. commit-authors $2 $3 | \
  54. grep -v --fixed-strings --file=${GIT_DIR}/author-whitelist
  55.  
  56. if test $? -eq 0; then
  57. # all is good
  58. echo ">>> Non-whitelisted Authors. Fail!" >&2
  59. exit 1
  60. fi
Add Comment
Please, Sign In to add comment