Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push over HTTP not activating remote hooks

Tags:

git

webdav

On my remote box, I've initialized a bare git repository. In the hooks directory, I've initialized the post-receive, post-update and update hooks with the following script:

#!/bin/bash
echo $0 $@ >> /tmp/githooks.log

On my local box, I've cloned the repository, added a test file, committed it and pushed the change back to the remote box.

$ git clone https://remote/git/sandbox.git sandbox
$ cd sandbox
$ touch asdf
$ git add asdf
$ git commit -a
[master (root-commit) 37505de] zxcv
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 asdf
$ git push origin master
Fetching remote heads...
  refs/
  refs/heads/
  refs/tags/
updating 'refs/heads/master'
  from 0000000000000000000000000000000000000000
  to   37505de9c22b0aee84e0071190f4f58728770675
    sending 3 objects
    done
Updating remote server info
To https://remote/git/sandbox.git
 * [new branch]      master -> master

However, /tmp/githooks.log is empty on the remote machine. If, however, I clone the repository while on the remote machine, the hooks are successfully called.

Do git hooks not work with http-push?

like image 382
Brad Beattie Avatar asked Dec 07 '10 00:12

Brad Beattie


People also ask

Can I push git hooks to remote?

You can import a remote Git repository in to Business Central and configure a post-commit Git hook to automatically push changes to that remote repository.

Does git push overwrite remote?

Only when you are up-to-date will you be able to push your own new commits to the remote. The --force option for git push allows you to override this rule: the commit history on the remote will be forcefully overwritten with your own local history.

Why git push is not working?

You need to use git pull and resolve the difference between your local changes and the remote changes before you can git push . There is still a commit in the remote branch initializing the repo that may not be in your local version.

Does git push push to all remotes?

Usually, we push changes by addressing remote name by default origin something like git push origin. You can configure group multiple remotes and give it a name. So you push to all those remotes by referring that name.


1 Answers

With Git protocols, you will have different features enabled.
For HTTP, this thread summarizes the issue:

The "problem" here (which is very much the way HTTP protocol was designed) is that it isn't git that updates repository on remote side on push (which knows about hooks), but web server via WebDAV.
And web server knows nothing about hooks.

Perhaps that would get improved when "smart" HTTP protocol gets implemented (currently in the phase of design, I think just after designing protocol).

As you commented, smart http would be the answer.

alt text

This feature is referred to as “smart” HTTP vs “dumb” HTTP because it requires having the Git binary installed on the server, where the previous incantation of HTTP transfer required only a simple webserver.
It has a real conversation with the client, rather than just dumbly pushing out data.

like image 75
VonC Avatar answered Oct 23 '22 08:10

VonC