I'm looking for possibilities to confirm whether the email address of the committer is lower case to avoid issues like this.
I'm thinking to implement a client side pre-commit hook script which would either convert the upper case into lower case characters in the username and email or just warns the user to change in git config.
I don't want to write something like this every time I encounter with errors during import. This is not recommended, as it results in modification in the ref values and might break some contents.
$ git filter-branch --env-filter 'export
GIT_AUTHOR_EMAIL="[email protected]";GIT_AUTHOR_NAME="Yourname"'
Please suggest me if there is any other better ways to achieve the same.
Client side hooks are not reliable IMO (the client could always pass in --no-verify, or just remove the hook completely). You'd want to use a server side hook that would reject any pushes that had commits with bad email addresses, and then print out recovery instructions for the end user on how to redo their commits with proper email addresses.
If you have existing commits in published history you don't have any non-destructive options for fixing those.
-A
This is a very rough sample that only correctly handles an existing branch update. You will need to add a lot more cases to handle new branches, deletes, tags, etc., as well as instructions on how they can configure their email and how to recreate the commits with correct email information. But it should get you started.
.git/hooks/update
refname="$1"
oldrev="$2"
newrev="$3"
for sha in $(git rev-list ${oldrev}..${newrev})
do
git log ${sha} --format="%ae %ce" -1 | grep [A-Z]
if [ $? -eq 0 ]
then
echo "SHA ${sha} contains an illegal email address containing uppercase characters"
git log ${sha} --format="%ae %ce" -1
exit 1
fi
done
If you try to push a SHA you will get something like this
remote: SHA 49511d51548720f774b4a2bed113c43d06c32a34 contains an illegal email address containing uppercase characters remote: [email protected] remote: error: hook declined to update refs/heads/master To /scratch/email_repo ! [remote rejected] master -> master (hook declined)