Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/usr/local/bin/bash
  2.  
  3. # Instructions: Rename .git/hooks/prepare-commit-msg.sample to
  4. # .git/hooks/prepare-commit-msg and add the contents of this file.
  5. # Make the file executable by typing "chmod u+x .git/hooks/prepare-commit-msg"
  6.  
  7. # This way you can customize which branches should be skipped when
  8. # prepending commit message.
  9. if [ -z "$BRANCHES_TO_SKIP" ]; then
  10. BRANCHES_TO_SKIP=(master develop test)
  11. fi
  12.  
  13. BRANCH_NAME=$(git symbolic-ref --short HEAD)
  14. BRANCH_NAME="${BRANCH_NAME##*/}"
  15.  
  16. BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
  17. BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
  18.  
  19. if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
  20. sed -i.bak -e "1s/^/${BRANCH_NAME^^} /" $1
  21. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement