Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't git have a pre-push hook?

Tags:

git

I would like to have a hook to run my tests before I push my changes to the remote (which sits on bitbucket).

I usually branch off master and when the feature is done I merge it back to master and push, which is why I was looking for the pre-push hook. Instead, I have used a post-merge & a pre-commit restricted to the master branch. I've seen that patch done for Git 1.6 and this other question that raises exactly my problem with it's proposed solution.

What I would like to know is why git does not support the pre-push hook then (especially if a patch has been accepted already once)? (btw - I'm on the latest git version)

like image 618
nieve Avatar asked Aug 31 '26 18:08

nieve


2 Answers

A patch for that hasn't been accepted, only submitted. And there's been another submitted within the last month or so.

If you follow the discussion thread that follows that patch submission, there is some discussion (example) about what would be needed for a patch that adds a pre-push hook to be acceptable. But that additional work hasn't been done in either the case of the patch to which you've linked nor with the more recent patch.

The patches that have been submitted so far have been judged as being no better than having a custom wrapper around the git push command. The maintainer of git doesn't want such an implementation of a hook to be added, making it more difficult to add a more useful implementation in the future without breaking compatibility.

like image 164
qqx Avatar answered Sep 02 '26 08:09

qqx


It, in my opinion, has always been a question of when and not why.

Git got the pre-push hook in the 1.8.2 release.

Sample pre-push script: https://github.com/git/git/blob/87c86dd14abe8db7d00b0df5661ef8cf147a72a3/templates/hooks--pre-push.sample

1.8.2 release notes talking about the new pre-push hook: https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.txt

like image 38
manojlds Avatar answered Sep 02 '26 06:09

manojlds