Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ## Description
  4. # This pre-commit git hook makes sure that a local username is defined if there is any remote repository on github.
  5. # This is helpful if you are working with multiple remote hosts and use different usernames. If you forget to configure
  6. # the local username you may end up sending a wrong username to your github remote.
  7. #
  8. # ## Usage
  9. # This is script is only useful if you make it available as a hook template. To achieve this, follow these steps:
  10. #
  11. # 1. Tell git to copy everything in ~/.git-templates to your per-project .git/ directory when you run git init or clone
  12. # git config --global init.templatedir '~/.git-templates'
  13. #
  14. # 2. Create a directory to hold the global hooks
  15. # mkdir -p ~/.git-templates/hooks
  16. #
  17. # 3. Move this script to `~/.git-templates/hooks/pre-commit`
  18. # Now every time you do a `git init` or `git clone` git will copy this script to the repository and executes it
  19. # before the commit is done.
  20.  
  21. RED='\033[0;31m' # red color
  22. NC='\033[0m' # no color
  23.  
  24. GITHUB_REMOTE=$(git remote -v | grep github.com)
  25. LOCAL_USERNAME=$(git config --local user.name)
  26.  
  27. if [ -n "$GITHUB_REMOTE" ] && [ -z "$LOCAL_USERNAME" ]; then
  28. printf "\n${RED}ATTENTION: At least one Github remote repository is configured, but no local username. "
  29. printf "Please define a local username that matches your Github account.${NC} [pre-commit hook]\n\n"
  30. exit 1
  31. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement