I am trying to get the commit message during the git pre push hook stage, but it is not retrieving the message during a git push from the git client side. I am trying to use the message to verify whether a push is allowed in a specific repo, and also get the issue number out of the commit message to use for checking Jira.
I based it off the example in the documents, but even checking which user is doing the git push is not working. I would expect it to have returned the hook response to the git client, or at least an error message to the log but I am not getting anything.
I’m currently using version 4.14 with the enterprise trial, does anyone have a working example of a git pre push hook for 4.14? Where can I find what properties of the commit I can access using the hook?
So I have tried that, and I am not getting the output of this
msg = ‘Commit {} was deployed to: {}’.format(last_commit, deploy_url)
to display on the client end. I have also tried copying the above code verbatim but it does not work. Is there somewhere I can see a full list of the kwargs I can access? Other than commit id I would like to be able to see the commit message
Did you restart rhodecode after changing the rcextensions? This is required to do. Also please check if you haven’t modify the git hooks by yourself, this would mean that the rcextensions aren’t executed.
Best to test this is to add something like raise Exception('test') to check if the push fails. If it doesn you can enter such url:
http://server.com/REPO_NAME/settings/advanced/hooks to re-install the hooks.
For getting the commit author/messages you’d need to extract this. There’s a helper in rcextensions for that.
from .helpers import extra_fields, extract_pre_commits
commit_list = extract_pre_commits.run(**kwargs)
for commit_data in commit_list:
message = commit_data['message']
I was referring to pre-receive/post-receive git hooks. Inside the repository. If you enter: http://server.com/REPO_NAME/settings/advanced/hooks RhodeCode will check them and fix if they are modified.
I was able to get raise Exception to be recognized after I restarted the service, but the example above does not work for responding to the git client with a message, I have tried copying the example verbatim.
In the extra fields in the repo, can the keywords be anything? I made a “test_url” keyword there and used it within the example, but I did not get output on the client side.
If that works and the extra_fields don’t we recommend upgrading to 4.15.X as there were some small fixes for that logic of rcextensions.
It’s very easy to upgrade and it should take you ~10minutes. Just make sure to get newer rcextensions in case it gives troubles now.
We’ve updated to 4.15.1, I am able to see some response to the hook changes when I do a git push when I try to push with “admin” or “root” but I tried the earlier example for the commit message and I am getting this error: