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