Git / gitosis:如何检查用户名和电子邮件的有效性? [英] Git/gitosis: How to check validity of user name and email?

查看:137
本文介绍了Git / gitosis:如何检查用户名和电子邮件的有效性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了git和gitosis,并且我需要添加一个检查,即将某些内容压入存储库时用户名是有效的。

I have installed git and gitosis and I need to add a check that the user name is valid when something is pushed into the repository.

我认为pre-receive hook是放置这个的正确钩子,但我无法找到gitosis进入存储库的真实用户名和电子邮件地址(由git config user.name和git config user.email设置的)来自环境变量。 LOGNAME和USER都是'git'。 gitosis如何检测这些信息,并且可以在pre-receive hook中找到它?

I reckon the pre-receive hook is the correct hook to place this, but I'm unable to find the real user name and email address which gitosis enters into the repository (the ones set by git config user.name and git config user.email) from environment variables. LOGNAME and USER are both 'git'. How does gitosis detect this info and can I find it in the pre-receive hook as well?

推荐答案

githooks(5) 收集 pre-receive hook会获得 stdin 的更新参考。

Hmm, from what I gather from githooks(5) the pre-receive hook gets fed the updated refs on stdin.

#!/bin/sh

while read old new name; do
    email=$(git log -1 --pretty=format:%ae $new)
    # check email
done

您需要检查电子邮件地址(可能有多行数据)并相应地退出脚本,即 exit 0 取得成功,例如退出1 失败。

You would need to check the email addresses (there can be more than one line of data) and exit the script accordingly, i.e. exit 0 for success and e.g. exit 1 for failure.

这篇关于Git / gitosis:如何检查用户名和电子邮件的有效性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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