Created
July 11, 2018 13:17
-
-
Save jumanjiman/75616ec91f115abba0cde6f47bea2cb4 to your computer and use it in GitHub Desktop.
pre-commit hook to check mailmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# Configure various overrides and exceptions in this file. | |
# See https://pre-commit.com/ for details. | |
fail_fast: false | |
repos: | |
- repo: local | |
hooks: | |
- id: check-mailmap | |
name: Detect if an email address needs to be added to mailmap | |
language: script | |
entry: ./check-mailmap | |
always_run: true | |
exclude: .* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -n "${DEBUG}" ]; then | |
set -x | |
fi | |
# Global return code. | |
RC=0 | |
main() { | |
check_email | |
} | |
check_email() { | |
# Check if any email address is associated with more than one name. | |
# | |
# Example: | |
# John Doe <[email protected]> | |
# jdoe <[email protected]> | |
# | |
# The above example can be fixed by adding these two lines to .mailmap file: | |
# John Doe <[email protected]> John Doe <[email protected]> | |
# John Doe <[email protected]> jdoe <[email protected]> | |
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
# How we want it to appear How it appears in git commit | |
# | |
# See git-shortlog(1) for more details. | |
output="$(! 2>&1 git log --use-mailmap --pretty='%aN %aE' | tr '[:upper:]' '[:lower:]' | sort -u | awk '{print $NF}' | sort | uniq -c | sed -e 's/^[ \t]*//' | grep -v '^1[[:space:]]' | awk '{print $NF}')" | |
if [ -n "${output}" ]; then | |
RC=1 | |
echo 'The following email addresses are associated with more than one name:' | |
echo | |
for email in ${output}; do | |
echo " ${email}" | |
done | |
echo | |
echo 'The associations include:' | |
for email in ${output}; do | |
echo | |
git log --pretty='%aN <%aE>' --regexp-ignore-case --author="${email}" | sort | uniq -c | |
done | |
fi | |
} | |
main | |
exit ${RC} |
I've added this hook to https://github.com/jumanjihouse/pre-commit-hooks#check-mailmap
Update .pre-commit-config.yaml
to include:
---
- repo: https://github.com/jumanjihouse/pre-commit-hooks
sha: 1.8.0
hooks:
- id: check-mailmap
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for a good condition
for a bad condition