Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 2.04 KB  |  views: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. # Helper hook to prevent folk from accidentally committing broken Puppet
  4. # manifests to the repository.
  5. #
  6. # You must have Ruby and Puppet installed on your workstation.  If a
  7. # local copy of the `puppet' program is not available, and you know what
  8. # you are doing, you may bypass this hook script at your own peril with:
  9. #
  10. #     $ git config anchor.im_a_puppet_master true
  11. #
  12. # or, for a once-off display of intrepidity, `git commit --no-verify'.
  13.  
  14. derp() {
  15.     echo "[$(basename ${0})] ${@}"
  16.     exit 1
  17. }
  18.  
  19. if git rev-parse --verify HEAD >/dev/null 2>&1; then
  20.     against=HEAD
  21. else
  22.     # Initial commit: diff against an empty tree object
  23.     against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
  24. fi
  25.  
  26. if [ "$(git config anchor.im_a_puppet_master)" = 'true' ]; then
  27.     # User has opted out of manifest verification
  28.     exit 0
  29. fi
  30.  
  31. if which puppet >/dev/null 2>&1; then
  32.     # Find the root of the Git repository.  The paths `git diff' spits
  33.     # out will be relative to this root.
  34.     OLD_PWD="$PWD"
  35.     while [ \! -d .git ]; do
  36.         if [ "$PWD" = "/" ]; then
  37.             cd "$OLD_PWD"
  38.             derp "I could not find the root of your Git repo."
  39.         fi
  40.         cd ..
  41.     done
  42.     IFS='
  43. '
  44.     boned=0
  45.     for MANIFEST in $(git diff --cached --name-only --diff-filter=AM \
  46.       $against | grep '\.pp$'); do
  47.         puppet --parseonly "$MANIFEST" || boned=1
  48.     done
  49.     cd "$OLD_PWD"
  50.     if [ $boned -ne 0 ]; then
  51.         derp "Aborting on broken manifest.  See feedback above."
  52.     fi
  53. else
  54.     cat - <<EOF
  55. Hey!  You don't have Puppet installed on your workstation!
  56.  
  57. Installing Puppet will allow me to automatically check your work for
  58. common typographical errors.  Without this check, your (potentially)
  59. broken manifests will make it out into the wild.  You will be left to
  60. waste your own time following-up with a correction, a new commit, and
  61. another roll-out.
  62.  
  63. If you would like to proceed anyway, punch this into your shell, and
  64. commit again:
  65.  
  66.     git config anchor.im_a_puppet_master true
  67.  
  68. EOF
  69.     derp "Aborting your commit because I could not find puppet."
  70. fi
clone this paste RAW Paste Data