dotfiles/dot_scripts/pre-commit-verify-committer.sh
MorganGeek 3a3fc30b8c fix technical debt + fine tune functions and hooks
- linting/fixing/formating
- utility for suggesting aliases now accepts parameters to change output
  size
- add helper to checkci
- add verify committer script to avoid committer with wrong git identify
2020-07-12 16:22:17 +02:00

32 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# shellcheck disable=SC1090
source "$HOME/.zsh_functions"
source "$HOME/.scripts/secrets.sh"
REMOTE=$(git config --get remote.origin.url)
USERNAME=$(git config --get user.name)
EMAIL=$(git config --get user.email)
checkEmailUsername() {
if [[ "$EMAIL" != "$1" ]]; then
warning "Invalid email: $EMAIL for remote $REMOTE"
arrow "fix this by running :\ngit config user.email $1"
exit 1
fi
if [[ "$USERNAME" != "$2" ]]; then
warning "Invalid username: $USERNAME for remote $REMOTE"
arrow "fix this by running :\ngit config user.name \"$2\""
exit 1
fi
}
if [[ $REMOTE == *"$COMPANY_NAME"* ]] && [[ "$REMOTE" != *"dotfiles"* ]]; then
checkEmailUsername "$GIT_PRO_EMAIL" "$GIT_PRO_USER"
else
checkEmailUsername "$GIT_PERSONAL_EMAIL" "$GIT_PERSONAL_USER"
fi