git: who pushed in post-receive hook

好久不见. 提交于 2019-12-05 09:15:53

If you're using the SSH protocol to push changes to the server, with each user having their own account on the server, then your script should be running as the user who's doing the push. So, you should be able to use whoami or id -un to get the username of the person doing the push.

If you are not using this setup, the best way to keep track of who is pushing is probably using Gitolite, a powerful Git authentication and authorization system. In Gitolite, you can use the update.secondary and post-update.secondary hooks, which will have the GL_USER environment variable set to the current Gitolite user.

I am not sure Git is meant to manage that kind of access control.

That is why you have ssh-based wrappers like gitosis or gitolite that will provide the adequate authentication level you are after.

You cannot tell that using Git. If you use SSH to push, then you can use SSH to get the username, if you use a user-management frontend such as gitolite, you can use that to get the username, if you use HTTP with authentication, you can use your webserver to get the username, but the Git networking protocols do not transmit any usernames.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!