如何强制用户在GIT中以小写字母使用电子邮件地址 [英] How to force users to use email address in lowercase in GIT

查看:165
本文介绍了如何强制用户在GIT中以小写字母使用电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找可能性来确认提交者的电子邮件地址是否小写,以避免像这个

我正在考虑实现一个客户端pre - 提交钩子脚本,它可以将大写字母转换成小写字母在用户名和电子邮件或只是警告用户改变在git配置。

我不每次遇到导入过程中的错误,都想写这样的东西。这不建议,因为它会导致ref值的修改,并可能会破坏一些内容。

  $ git filter-branch  - -env-filter'export 
GIT_AUTHOR_EMAIL =yourname@example.com; GIT_AUTHOR_NAME =Yourname'

请建议我是否还有其他更好的方法来实现。

解决方案

客户端挂钩可靠的国际海事组织(客户可以随时通过 - 无验证,或只是完全删除钩)。您希望使用服务器端钩子,该钩子会拒绝任何已经提交了错误电子邮件地址的推送,然后为最终用户打印恢复指令,以了解如何使用正确的电子邮件地址重新提交它们的提交。



如果您在已发布的历史记录中有现有的提交,那么您没有任何修复这些提交的非破坏性选项。

-A



这是一个非常粗略的示例,只能正确处理现有的分支更新。您将需要添加更多的案例来处理新的分支机构,删除,标签等,以及如何配置其电子邮件以及如何使用正确的电子邮件信息重新创建提交的说明。但它应该让你开始。



.git / hooks / update

 <$ c $ g> rev-list $ {oldrev} .. $ {$> $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' newrev})
do
git log $ {sha} --format =%ae%ce-1 | grep [A-Z]
if [$? -eq 0]
然后
echoSHA $ {sha}包含一个非法的电子邮件地址,其中包含大写字母
git log $ {sha} --format =%ae%ce - 1
exit 1
fi
done

如果您尝试推一个SHA你会得到这样的东西


远程:SHA 49511d51548720f774b4a2bed113c43d06c32a34包含一个
非法的电子邮件地址包含大写字母远程:
AndrewC@whoops.com远程:错误:钩拒绝更新
refs / heads / master到/ scratch / email_repo! [远程拒绝] master
- > master(钩子拒绝)


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="yourname@example.com";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: AndrewC@whoops.com remote: error: hook declined to update refs/heads/master To /scratch/email_repo ! [remote rejected] master -> master (hook declined)

这篇关于如何强制用户在GIT中以小写字母使用电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆