The hook post-update doesn't work automatically. Manually it works fine

242 views
Skip to first unread message

frank....@gmail.com

unread,
Aug 13, 2015, 9:10:43 AM8/13/15
to Git for Windows
Hi,

git:  git 1.9.5-preview20150319
os:  windows 7 pro.

at server side...
I have installed a git server, as a war file (gitblit.war), on my tomcat server.

at client-side...
I have a repository (R1) where i do all the modifications before committing and manually pushing it to the server (git push origin test)
I have a second one, (R2) which only gets automatically the last modifications: git pull origin test
(Y:\Myprod\diff-gitstore\myprogs)

The automatic pull is done through the post-update hook which resides under the R1 repository:

Y:\Myprod\gitstore\myprogs\.git\hooks\post-update
here is the content:
------------------------------------------------
#!/bin/sh

cd /Y/Myprod/diff-gitstore/myprogs

echo "git pull from server ... test branch"

unset GIT_DIR

git pull origin test
-------------------------------------------------
I expect that, after pushing manually the modifications, the script automatically runs and pull modifications to R2.
It doesn't.

If i run it manually (./post-update ), it's ok.

Am I wrong in thinking that post-update has to automatically run when a push occurs ?
Where is the problem ?

Thanks and regards


Johannes Schindelin

unread,
Aug 13, 2015, 10:39:48 AM8/13/15
to frank....@gmail.com, Git for Windows
Hi Frank,

On 2015-08-13 14:22, frank....@gmail.com wrote:

> I have a repository (R1) where i do all the modifications before
> committing
> and manually pushing it to the server (git push origin test)
> I have a second one, (R2) which only gets automatically the last
> modifications: git pull origin test
> (Y:\Myprod\diff-gitstore\myprogs)
>
> The automatic pull is done through the post-update hook which resides
> under
> the R1 repository:
>
> Y:\Myprod\gitstore\myprogs\.git\hooks\post-update
> here is the content:
> ------------------------------------------------
> #!/bin/sh
>
> cd /Y/Myprod/diff-gitstore/myprogs
>
> echo "git pull from server ... test branch"
>
> unset GIT_DIR
>
> git pull origin test
> -------------------------------------------------
> I expect that, after pushing manually the modifications, the script
> automatically runs and pull modifications to R2.
> It doesn't.

From https://www.kernel.org/pub/software/scm/git/docs/githooks.html:

> post-update
>
> This hook is invoked by git-receive-pack on the remote repository,
> which happens when a git push is done on a local repository. It
> executes on the remote repository once after all the refs have been
> updated.

In other words, the `post-update` hook will not be called on the
*client* but on the *server* side (but maybe not in Git Blit, either,
because it is a pure Java solution. At least from glancing at
http://gitblit.com/setup_hooks.html it does not seem as if you could use
shell scripts as hooks (and you would still have the problem that you
want to run a program on the *client* side, which the *server*'s hook
cannot trigger).

Ciao,
Johannes

Frank Vestris

unread,
Aug 14, 2015, 5:39:24 AM8/14/15
to Git for Windows
Hi Johannes,

thanks for your answer.

Actually, you're right.
I've read at git-scm.com/docs/githooks the meaning of the post-update hook and the fact that is invoked on the remote repository but I did not find any hook which could be invoked at client side when modifications are pushed to the server.

I've checked all the local repositories and all have the same hooks examples under REPOS/.git/hooks :
applypatch-msg.sample,commit-msg.sample,post-update.sample,pre-applypatch.sample,pre-commit.sample,prepare-commit-msg.sample,pre-push.sample,pre-rebase.sample,update.sample.

First, I'm surprised to see hooks that have to be invoked at server side. The only one (if i've well understood) which can be run at client side, is commit-msg.
It seems like there's no means to run a hook on local side when new modifications have been pushed to the server.

So, any idea on what could be done ?

Regards
Frank
Reply all
Reply to author
Forward
0 new messages