1

I am trying to implement git hook commit on a server using these instructions: https://git-scm.com/book/be/v2/Customizing-Git-An-Example-Git-Enforced-Policy

I created file "update" (make it executable, put in hooks folder), and found that this file is not executed when I do git commit -m "my message" and git push - all these commands work perfectly, but 'update' file is not working (I tried with simple script "echo "Hello World" >> somefile.txt)

Where is the problem?

Brian
  • 14,610
  • 7
  • 35
  • 43
Lavrentijs L
  • 119
  • 1
  • 8
  • Have you put the hook into the remote (server) repository? And certainly, update hooks works only on the remote side, on receiving commits from a client, so `git commit` isn't involved at all. – user3159253 Dec 07 '15 at 16:29
  • Yes, I put hook "update" file on server, but it does not work when I "git commit"! – Lavrentijs L Dec 07 '15 at 18:31
  • `git commit` is a completely _local_ operation. It doesn't involve any network transaction, only `git push`, `git fetch` and `git pull` which is essentially `git fetch` + `git merge` do. – user3159253 Dec 08 '15 at 00:18
  • What exactly are you trying to achieve with the hooks? – user3159253 Dec 08 '15 at 00:21
  • I want to implement that all commits begin with ticket numbers: "TicketNumber-1234" I understand that "git commit" is local one. When I do "git push", my "update" script is not running at all. My repo path is /path/test.git/hooks - there I put "update" file. – Lavrentijs L Dec 08 '15 at 09:06
  • I found similar ticket http://stackoverflow.com/questions/4372306/git-push-over-http-not-activating-remote-hooks = same case as I described above. But when I switched to SSH protocol, it does not work anyway. – Lavrentijs L Dec 08 '15 at 16:15

1 Answers1

1

As commented above, the update hook is a server side hook

It needs to be on the server you are pushing to, in the bare repo: repo.git/hook/update

That explains why a git commit (local operation) does not trigger the server side hook.

For the rest, see the follow-up question.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250