Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

install-hooks.sh 907B

12345678910111213141516171819202122
  1. #!/bin/bash
  2. HOOK_NAMES="pre-commit"
  3. HOOK_DIR=$(git rev-parse --show-toplevel)/.git/hooks
  4. INSTALL_DIR=$(git rev-parse --show-toplevel)/hooks
  5. COLOR_GREEN=`tput setaf 2`
  6. COLOR_RESET=`tput sgr0`
  7. for hook in $HOOK_NAMES; do
  8. echo -n "Installing $hook hook..."
  9. # If the hook already exists, is executable, and is not a symlink
  10. if [ ! -h $HOOK_DIR/$hook -a -x $HOOK_DIR/$hook ]; then
  11. echo -n " Hook already exists, saving old hook backup at $HOOK_DIR/$hook.local..."
  12. mv $HOOK_DIR/$hook $HOOK_DIR/$hook.local
  13. fi
  14. # create the symlink, overwriting the file if it exists
  15. # probably the only way this would happen is if you're using an old version of git
  16. # -- back when the sample hooks were not executable, instead of being named ____.sample
  17. echo -n " Creating symlink..."
  18. ln -s -f $INSTALL_DIR/$hook $HOOK_DIR
  19. echo "${COLOR_GREEN} Done! ✓${COLOR_RESET}"
  20. done