2

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)

Community
  • 1
  • 1
nieve
  • 4,601
  • 3
  • 20
  • 26

2 Answers2

5

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.

qqx
  • 18,947
  • 4
  • 64
  • 68
  • Wasn't aware of the more recent patch (http://thread.gmane.org/gmane.comp.version-control.git/209897/focus=209934). I'm still not 100% convinced by the arguments found in these threads. This is rather annoying; I think Scott Chacon makes a very good case. – nieve Dec 19 '12 at 22:06
  • @nieve a pre-push hook would anyway be something that has to be configured on the user end, so why wouldn't you just use an alias for the time being, when you anyway would have to fiddle with local user configuration? – eis Dec 19 '12 at 22:10
  • @eis I'll definitely have a look at using an alias, it's just weird to have a script to decide if I want to run the tests and if so do that and call it from the alias. Also, I will have to remember when to use my alias and when to use git push, not ideal. Also, what did you mean by fiddle with local user config? it's just a script inside a pre-push file. – nieve Dec 19 '12 at 22:21
  • Edit your answer, I'll be more than happy to give you back the credit! You deserve it more than anyone else. – nieve Feb 21 '13 at 20:32
4

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

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 3
    It's somewhat amusing that this answer caused my answer to be unaccepted, since I contributed the code to add support for the `pre-push` hook. – qqx Feb 04 '13 at 16:30