How do I properly set up hooks on a remote that is specified via the file:// protocol?
Say I’ve got an upstream repo (
origin) that was added with
git remote add origin file:////upstream.host/repo.git
repo.git is acually a windows shared folder where I and my dev colleagues have r/w access assigned.
Now, I want to set up a
post-receive hook on
upstream.host that notifies Trac about freshly pushed revisions for automatic ticket updating. Basically, this is done by calling an executable on
upstream.host that does some work in the database there.
However, I notified that the hook for some reason doesn’t work.
So I’ve set up the hook to print everything she’s doing to
D:/temp/post-receive.log and issued a
git push in order to trigger the hook.
When I looked into
upstream.host, there was no logfile created.
Then, another question of me came into mind: https://superuser.com/questions/974337/when-i-run-a-git-hook-in-a-repo-on-a-network-share-which-binaries-are-used.
When actually the binaries of my machine are used for executing the hook, maybe also the paths of my machine are used. I looked into
D:/temp and voilá, here we have the
I traced the
pwd to the logfile and it is not
D:/repos/repo.git (what I expected) but actually is
//upstream.host/repo.git. Obviously the whole hook is executed in the context of the pusher’s machine and not in the context of the repo machine (
This is no problem for me since I have admin access to the remote machine and could use administrative shares in order to get my hook going (i.e.
\\upstream.host\D$\repos\repo.git etc). But this is an issue for my colleagues since they are plain users and no roots.
How do I set up my
post-receive hook properly so that it works as expected?
How do I force my hook to be entirely run on the remote machine without using anything from my machine?
Do I really have to implement a real server hosting my repo? Or are there other ways that don’t need a server?
One Solution collect form web for “How do I properly set up hooks on a remote that is specified via the file:// protocol?”
post-receive hook is run after receiving data on the machine that is hosting the repository.
now the machine that is “hosting the repository” is not the file-server where the actual
packed-refs and other git database files are stored. (this file-server could be anything from a redundant cloud-based storage appliance to any old NAS-enabled “network disk”).
Instead it is the machine that runs the “git frontend” (that is, the git commands that actually interact with the database).
Now you are using a “network share” to host your (remote) git repository. For your computer (the client), this is just another disk device (like your floppy) and the git on your client will happily store database-files there, and run any hooks. But this is your computer, since it is being told to run the remote locally – simply because the
file:// protocol does mean “local”.
Btw, the fact that your remote is named
upstream.host is meaningless: this name is only there for you to keep track of multiple remotes, but it could be called
So there is no way to run any script on the file-server that happens to store some files names
pack-refs and similar.
If you want to have a git server to run hooks for you, you must have a git server first. Even worse: if you want a git server on machineX to run scripts on machineX, you must install a git server on machineX first.
The good news: there is no need to “implement a real server”. Just install a pre-existing one. You will find docuementation about that in the Git Book, but for starters it’s basically enough to have
git (for interaction with the database) and
sshd (for secure communication via the network; and for calling
git when appropriate) installed.
Finally: i’m actually quite glad that you need to have software (e.g. a server) running on the remote end to execute code there. Just imagine what it would mean if copying some html files to your USB disk would suddenly spawn a web server out of thin air. Not to think of w32-virusses breeding happily on my linux NAS…