Issue #339 resolved

'pre-receive' Git hook is executed in a wrong way

dmitry-pavlenko
created an issue

According to http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Server-Side-Hooks

'pre-receive' should be executed once per "git push" command, it shouldn't use command line arguments and should read the list of changed references from stdin:

<old-sha1> <new-sha1> <reference>
<old-sha1> <new-sha1> <reference>
...
<old-sha1> <new-sha1> <reference>

And if the hook exist with non-zero exit code, the whole push is rejected.

But currently it is executed by scm-manager once per reference (like Git 'update' hook) with command line arguments <old-sha1> <new-sha1> <reference> instead of stdin.

I didn't test but it's worth looking at other hooks like 'post-receive' (that has the same args and input as 'pre-receive', can't reject pushes) and 'update' (is invoked once per reference, accepts 3 arguments <old-sha1> <new-sha1> <reference>, can reject individual reference updates).

I'm trying to use SubGit with scm-manager but it relies on the way 'pre-receive' and 'post-receive' hooks are executed.

Comments (8)

  1. dmitry-pavlenko reporter

    Thanks now the hooks are nearly perfect. 'update' exit code still is not respected, but this hook is not used by SubGit, so doesn't matter for me.

    One minor difference compared to native Git. If 'pre-receive' hook exits with 1, I get this

    $ git push 
    Password for 'http://scmadmin@localhost:8080': 
    To http://scmadmin@localhost:8080/scm/git/test
     ! [remote rejected] branch5 -> branch5 (unspecified reason)
    error: failed to push some refs to 'http://scmadmin@localhost:8080/scm/git/test'
    

    but native Git server returns "(hook declined)" as reason. But this difference is in aesthetics only.

    Thank you for very quick fix once again.

  2. Log in to comment