如何在服务器端git hook中获取推送用户信息?

Sur*_*ddy 4 git githooks

我想阻止用户通过使用服务器端hooks(update hook)删除远程git分支。

我已经在更新挂钩中编写了shell脚本来实现这一目标。
现在我可以停止所有用户删除远程git分支,但是我想授予特定用户删除权限,为此,我们需要获取在服务器端挂钩中尝试删除操作的用户的用户信息(用户名,useremail) ?

我们有$USER, $GIT_AUTHOR_NAME, $GIT_AUTHOR_EMAILetc变量来获取客户端挂钩中的用户信息,但是它们在服务器挂钩中没有用。

我们还有其他选择可以在服务器端挂钩中获取用户信息吗?

Cod*_*ard 6

Sample hook code

请记住,每个人都可以使用以下方法伪造电子邮件:

git commit -c user.name ... -c user.email ...
Run Code Online (Sandbox Code Playgroud)

为了避免它到达您的中央仓库文档,并读取bout用户权限(在每个服务器之间有所不同),并从那里提取如何获取用户详细信息的信息。

#!/bin/sh
#

# Extract the desired information from the log message
# You can also use the information passed out by the central repo if its available

# %ae = Extract the user email from the last commit (author email)
USER_EMAIL=$(git log -1 --format=format:%ae HEAD)

# %an = Extract the username from the last commit (author name)
USER_NAME=$(git log -1 --format=format:%an HEAD)

# or use those values if you have them:
# $USER, $GIT_AUTHOR_NAME, $GIT_AUTHOR_EMAIL

#
#... Check the branches and whatever you want to do ...
#

# personal touch :-)
echo "                                         "
echo "                   |ZZzzz                "
echo "                   |                     "
echo "                   |                     "
echo "      |ZZzzz      /^\            |ZZzzz  "
echo "      |          |~~~|           |       "
echo "      |        |-     -|        / \      "
echo "     /^\       |[]+    |       |^^^|     "
echo "  |^^^^^^^|    |    +[]|       |   |     "
echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
echo "  |       |  []   /^\   []   |+[]+   |   "
echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
echo "  |[]+    |      || ||       |[]+    |   "
echo "  |_______|------------------|_______|   "
echo "                                         "
echo "                                         "
Run Code Online (Sandbox Code Playgroud)


Sur*_*ddy 1

在这里我得到了解决方案。

https://github.com/jakubgarfield/Bonobo-Git-Server/issues/494

我们使用 bonobo git 服务器作为版本控制。