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?
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 " "
Here I got the solution.
https://github.com/jakubgarfield/Bonobo-Git-Server/issues/494
We are using bonobo git server as a version control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With