2

I have Git 1.9.5 on Windows 7 x64. Assume the Git server is running the same version and the same OS on the same network. Is there a way to access the committer or author from a pre-receive or update server-side hook without the use of SSH?

From my understanding, after reading the man pages, it seems like SSH is required in order to set an environment variable on the server that would contain the user's name. And also the pre-recieve and update hooks typically only receive arguments from stdin or command line argv, at most, the name of the reference (branch), the SHA-1 that reference pointed to before the push, and the SHA-1 the user is trying to push.

solstice333
  • 3,399
  • 1
  • 31
  • 28

2 Answers2

2

Git doesn't deal with authentication (or authorization for that matter, which is why you have frameworks like gitolite)

So unless you have a listener (ssh or even https) which sets en environment variable with the identified user id in it, a hook (or any other git part) wouldn't know who did what.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • From what I found, it seems like SSH/Cygwin/Gitolite is the way to go similar to what is described in this article: http://therightstuff.de/2010/03/28/How-To-Set-Up-A-Git-Server-On-Windows-Using-Cygwin-And-Gitolite.aspx – solstice333 Aug 29 '15 at 06:21
1

If you are satisfied with the metadata contained in the commit you may use something like this in a pre-receive hook:

#! /bin/sh

while read oldrev newrev refname
do
    author="$(git show --quiet --format="%aN <%aE>" $newrev)"
    committer="$(git show --quiet --format="%cN <%cE>" $newrev)"

    echo "Author: $author Commiter: $committer"
    exit 0
done
joran
  • 2,815
  • 16
  • 18