Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force users to use email address in lowercase in GIT

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.

like image 203
Jeyanthan I Avatar asked Jul 02 '14 20:07

Jeyanthan I


People also ask

Is git add case-sensitive?

Git was built originally to be the Linux kernel's version control system, so unsurprisingly, it's case-sensitive.

What is users Noreply github com?

If you created your account on GitHub.com prior to July 18, 2017, your noreply email address from GitHub is [email protected] . You can get an ID-based noreply email address for GitHub by selecting (or deselecting and reselecting) Keep my email address private in your email settings.

Can you use Git without email?

When contributing to github, always use the anonymous noreply email address provided by github - which you can find here: https://github.com/settings/emails (have to tick "Keep my email addresses private" to see it). If using github or even if you're not, this is a better option than setting no email.


2 Answers

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)

like image 198
Andrew C Avatar answered Sep 19 '22 12:09

Andrew C


I am not sure is it off-topic but why you have to force users to use email in lowercase? The local-part (part before @) of email address can be case sensitive.

[email protected] and [email protected] can be a different email address and it's all depending on serverA.com.

See RFC

Verbs and argument values (e.g., "TO:" or "to:" in the RCPT command and extension name keywords) are not case sensitive, with the sole exception in this specification of a mailbox local-part (SMTP Extensions may explicitly specify case-sensitive elements). That is, a command verb, an argument value other than a mailbox local-part, and free form text MAY be encoded in upper case, lower case, or any mixture of upper and lower case with no impact on its meaning. The local-part of a mailbox MUST BE treated as case sensitive.

https://www.rfc-editor.org/rfc/rfc5321#section-2.4

http://en.wikipedia.org/wiki/Email_address#Common_local-part_semantics

If you find any problem importing upper case email address, i think it is NOT to address this issue in git but should be on that importing program

like image 24
palazzo train Avatar answered Sep 18 '22 12:09

palazzo train