2

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 <“myemail@gmail.com”>
Date:   Sat Oct 26 18:06:06 2019 -0400

    Write Makefile and hooks

commit 484c283a9faf0afed14328c9b71e635338c86187 (production)
Author: “Malek <“myemail@gmail.com”>
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?

Whiteclaws
  • 902
  • 10
  • 31
  • 1
    hooks are for repo administration, if you want people pushing hooks to your repo it's easy to set up (with your own hooks) but repo administration is not the same as tracking content. – jthill Oct 26 '19 at 22:27
  • @jthill 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... – Whiteclaws Oct 26 '19 at 22:34
  • What led you to believe that symbolic links are added or checked out as anything but symbolic links? edit: also, the defining characteristic of a bare repository is it doesn't do any checkouts at all, all content is kept packed. – jthill Oct 28 '19 at 00:14

1 Answers1

4

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).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Should've specified in the question, but this is a Linux-related inquiry. But yep, copying the hook definitely fixed the problem for me. – Whiteclaws Oct 26 '19 at 23:03
  • @Whiteclaws OK. I have rewritten the answer to remove any mention of Windows. – VonC Oct 26 '19 at 23:08