我想阻止用户使用服务器端挂钩删除远程 git 分支(更新钩子).
我在 update hook 中编写了 shell 脚本来实现这一点。
现在我可以停下来了all用户删除远程git分支,但我想授予删除权限特定用户,为此,我们需要获取正在服务器端挂钩中尝试删除操作的用户信息(用户名、用户邮箱)?
we have $USER, $GIT_AUTHOR_NAME, $GIT_AUTHOR_EMAIL
等变量在客户端挂钩中获取用户信息,但它们在服务器端挂钩中没有用。
我们还有其他选项可以在服务器端挂钩中获取用户信息吗?
Sample hook code
请记住,每个人都可以通过以下方式伪造提交中的电子邮件:
git commit -c user.name ... -c user.email ...
为了避免它,请访问您的中央存储库文档并阅读用户权限(每个服务器之间有所不同)并从那里提取如何获取用户详细信息的信息。
#!/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 " "
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)