Git: Is it valid (and presumably forward compatible) to use non-email strings in the user.email config?

Viewed 34

The following works:

$ git config --local user.email "icq: 1234"

$ git commit --allow-empty -m "test"
[master 6d21d58] test

$ git cat-file -p HEAD
tree 6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321
parent 3ea7111c6fda5a46bf1ccfd9193d483facb29356d7d9c833c54ba95265c58c55
author John Doe <icq: 1234> 1614734711 +0100
committer John Doe <icq: 1234> 1614734711 +0100

test

My question is whether this is properly supported by git or whether this is undefined behaviour, and whether it's reasonable to assume that a commit generated with a user.email that is not a valid e-mail string is going to remain a valid git commit in future versions of git?

1 Answers

Git is very lenient on the user.email field because the production for email addresses is very complex and implementing a real parser would be very difficult in C without some sort of generator. So this syntax is currently accepted and it will probably, for that reason, continue to be accepted in the future.

However, many other tools and languages that use Git do definitely assume that it is a deliverable email address. For example, if you use GitHub, it associates commits with your account based on your email address, and you'll need to verify that address by sending mail to it, so these values won't be accepted.

In addition, whitespace poses a problem, because Git uses the .mailmap in a lot of cases to rewrite older or incorrect names and email addresses. Such a syntax might not be gracefully accepted by Git or the variety of tools which parse that format, and so it's best not to do that. While patches would probably be issued for Git if it itself had a problem parsing email addresses with spaces, in general the assumption many people have, albeit an incorrect one, is that email addresses don't contain spaces.

As a consequence, while Git accepts this, I would not rely on it continuing to work robustly in most cases. If you can rewrite the ICQ address in this case as an email address, that would be better.

Related