Reputation: 942
I have a bare repository on a host machine and a local repository on my laptop. I have 2 hooks: one pre-commit and one post-receive hook. Both are in my local hook folder:
malek@laptop:~/Desktop/portfolio-website/.git/hooks$ ls
post-receive pre-commit
And of course, I push my local repository to the remote repository (my local pre-commit hook works fine) but my hooks are not updated on my bare remote repository.
malek@laptop:~/Desktop/portfolio-website/.git/hooks$ git push -u origin --all
Branch 'master' set up to track remote branch 'master' from 'origin'.
Branch 'production' set up to track remote branch 'production' from 'origin'.
Everything up-to-date
As you can see below:
malek@localhost:~/portfolio-website/hooks$ ls
applypatch-msg.sample pre-applypatch.sample pre-rebase.sample
commit-msg.sample pre-commit.sample pre-receive.sample
fsmonitor-watchman.sample prepare-commit-msg.sample update.sample
post-update.sample pre-push.sample
The git log master
command returns
commit 3403657fc4d08f406416711255cf04390a2df070 (HEAD -> master)
Author: “Malek <“[email protected]”>
Date: Sat Oct 26 18:06:06 2019 -0400
Write Makefile and hooks
commit 484c283a9faf0afed14328c9b71e635338c86187 (production)
Author: “Malek <“[email protected]”>
Date: Tue Oct 22 00:17:11 2019 -0400
Master branch creation
Why aren't my hooks updated on my remote repository if the commit was sent successfully?
Upvotes: 2
Views: 1262
Reputation: 1323953
A pre-commit hook is a client side hook, which will remain (like any hook) in your local repository;
A post-receive hook is a server-side hook, which must be installed/copied manually on the remote repo (even if that remote repository is on the same machine).
I have a soft symbolic link to my hooks folder in my project's directory so I would assume that those hooks would be updated on the bare repository as well..
Since the hook is not part of what is pushed (for security reason), that symlink will not be replicated on the remote repository.
Hence the need to copy manually the post-receive hook (not the pre-commit one, which would not work in a bare repository anyway).
Upvotes: 4