Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # abort if .git-hooks is not present
  2. # add .git-hooks to .git-ignore so people can opt-in
  3. if [ ! -f .git-hooks ]; then
  4. exit 0
  5. fi
  6.  
  7. # some commit operations we dont want to prefix the message
  8. if [[ "$2" == "merge" || "$2" == "commit" || "$2" == "template" || "$2" == "squash" ]]; then
  9. echo "Not a regular commit so ignoring.."
  10. exit 0
  11. fi
  12.  
  13. # get initials from the dev's GIT config
  14. # got to be a tidier regex for this
  15. initials=$(git var GIT_AUTHOR_IDENT | sed 's/^\([A-Za-z]\{1\}\).* \([A-Za-z]\{1\}\).*$/\1\2/')
  16.  
  17. ##
  18. # override the prefix
  19. ##
  20.  
  21. # 1. default is just the dev's initials
  22. prefix="[$initials][]"
  23.  
  24. # 2. dev is continuing a line of commits on the same ticket (i.e not after a merge or after someone elses line of commits)
  25. # [RS DW][MR-312] updated... -> extract [RS DW][MR-312]
  26. # [DW JR][MR-310] send.... -> ignore
  27. # Merged branch... -> ignore
  28.  
  29. regex="^\[${initials}"
  30. match=$(git log -1 --pretty=%B | grep -e "$regex")
  31.  
  32. if [ -n "$match" ]; then
  33. prefix=$(git log -1 --pretty=%B | sed 's/^\(\[.*\]\).*$/\1/')
  34. fi
  35.  
  36.  
  37. # add prefix
  38. echo "$prefix\n$(cat $1)" > "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement