Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get push user information in server side git hook?

Tags:

git

githooks

I would like to stop users to delete remote git branch by using server side hooks(update hook).

I have written shell script in update hook to achieve that.
Now I am able to stop all users to delete remote git branch, but I want to give delete permission to specific user, to do this we need to get user information(username, useremail) of who is trying the delete operation in server side hook?

we have $USER, $GIT_AUTHOR_NAME, $GIT_AUTHOR_EMAIL etc variables to get user information in client side hooks, but they are not useful in server side hooks.

Do we have any other options to get user info in server-side hooks?

like image 384
Surendra Reddy Avatar asked Mar 01 '16 09:03

Surendra Reddy


2 Answers

Sample hook code

Keep in mind that everyone can fake the email in the commit with:

git commit -c user.name ... -c user.email ...

To avoid it got to your central repo documentation and read bout user permissions (vary between each server) and extract from there the info how to fetch user details.

#!/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 "                                         "
like image 169
CodeWizard Avatar answered Sep 21 '22 17:09

CodeWizard


Here I got the solution.

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

We are using bonobo git server as a version control.

like image 39
Surendra Reddy Avatar answered Sep 21 '22 17:09

Surendra Reddy