Reputation: 341
Is there any way I can access the commit author information (author name and email) from Git commit-msg
hook?
I need to prevent commits which do not have the right email address (like [email protected]
). I can do this on the server side with the pre-receive
hook or the update
hook, but is there any way to do the same on the client side?
Of course, I could run
git log -1 HEAD
in the post-commit
hook and parse the output, but it's already too late, because the commit has already been created, at that stage. It can only serve as a friendly warning that the push will fail.
Upvotes: 1
Views: 406
Reputation: 12403
How about using a git var
command? For example:
$ export EMAIL="[email protected]"
$ git var GIT_AUTHOR_IDENT | grep -E -o "<.+>" | sed 's,<,,' | sed 's,>,,'
[email protected]
$ unset EMAIL
$ git var GIT_AUTHOR_IDENT | grep -E -o "<.+>" | sed 's,<,,' | sed 's,>,,'
ja@AMDC689
Modify ~/.gitconfig:
[user] email = [email protected]
$ git var GIT_AUTHOR_IDENT | grep -E -o "<.+>" | sed 's,<,,' | sed 's,>,,'
[email protected]
Upvotes: 2