It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Any tricks to get the authenticated user in git hook script?

As stash is on the way of adding more strong permissions controls, we are thinking of implementing a branch level ACL based on Git Hook scripts when people doing push.

But we stuck at how to get the actual user who is issuing the push, the $USER always returns the Stash instance user, which makes sense, as it is the user who eventually run the "git" commands.

But is there anyone we could get the actual authenticated user (name or email) in hooks?


3 answers

1 vote

Hi Chris,

It's currently not possible to get the authenticated user from Stash in a git hook script, but it should be a small change to make the information available. I can see how this would be useful for almost any hook script, so I hope we can make the fix available soon.

I've opened a Jira issue for this (; please watch the issue to follow our progress.



I got post hook emails to work by adding variables to the hook. This

<stash_home>/data/repositories/<repo num>/hooks/post-receive

# An example hook script for the "post-receive" event.
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated.  It is passed arguments in through
# stdin in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".
USER_EMAIL=$(git log -1 --format=format:%ae HEAD)
USER_NAME=$(git log -1 --format=format:%an HEAD)
. /usr/share/git/contrib/hooks/post-receive-email

Thanks for your answer.

But I was referring to a different problem...

We could get the comitter's info from the git log, however, we can't get the pusher's info ... namely, the person who performed the push ...

THe pusher could be different from the commiter ...

So your committer and pusher could be the same person with different usernames? Otherwise author is the person that makes the change and committer is the integrator that pushes to the central repository.

yeah, in my case, the person who makes the change, and the integrator who do the push are different.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Mar 14, 2019 in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

974 views 1 16
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you