3

I would like to provide integration hooks on top of Git such that pushes get rejected when the integration failed. For example when a developer pushes his changes, I would like to check that the project still compiles successfully.

Presently, I setup the post-update hook to do the compilation checking. However when I want to reject the push, I revert the changes and inform the developer about it :

git revert --no-edit HEAD
echo "Rejected !"

My issue is that when another developer wants to push his changes, he has to pull first thus overriding his work and then needs to issue painful reset/stash commands to merge correctly.
Moreover, the revert will not work in case of branch merging (which needs the -m option)

My current workaround is that instead of reverting on the server, I merge the changes in another branch (which is the default pull origin for my developers):

git checkout integrated
git merge master

What is the best approach to achieve this goal ?

3XX0
  • 1,315
  • 1
  • 13
  • 25
  • Enable your developers to run the test-suite locally. You could automate this with a pre-commit hook. If error get pushed anyway, just make an ordinary revert commit or a commit fixing the error and live with that. Making pushes last for minutes because CI has to run before they are allowed sounds like a very bad idea to me. – innaM Jun 22 '13 at 10:37

1 Answers1

3

Best approach for this would be giving developers their own feature branches which have post-update hook that checks the compiling and then merges it into master (If you want to go all paranoid on this you can make the hook push to another branch which you merge to master manually). This way you don't have to worry about it being rejected. In my opinion master should be only used as a release branch a reference point not something that everyone pushes everything to.

Learath2
  • 20,023
  • 2
  • 20
  • 30
  • 1
    Maybe OP should look into using Jenkins. It sounds like it can be set up to support this scenario with "Merge before build". See https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-AdvancedFeatures – Klas Mellbourn Jun 22 '13 at 11:30
  • Well I only went with post-update hooks as he said he used them in his question but Jenkins can be used too. – Learath2 Jun 22 '13 at 11:52
  • Thanks ! I wanted to avoid extra dependencies but yeah maybe Jenkins is the right thing to do – 3XX0 Jun 22 '13 at 12:00