Git pre-push hook unable to get unpushed commit info

Rhodecode version: 4.12.4
Git version: 2.16.4

I’m attempting to extract and validate commit messages during a pre-push hook. I’m using the extract_pre_commit helper file to get the commit messages and get an error:

git_env = dict(data[‘git_env’])
Exception: Got remote exception “KeyError” with args “[‘git_env’]”

My results of kwargs[‘commit_ids’]:
[{u’ref’: u’filler_data’,
u’type’: u’filler_data’,
u’old_rev’: u’filler_data’,
u’name’: u’filler_data’,
u’new_rev’: u’filler_data’}]

I assume I’m missing [‘git_env’] due to my rhodecode version. Is this correct? When I remove all git_env variables I’m only able to get the commits within the remote repo.

Any help is appriciated.

Hi! Can you provide full log for this issue?
Also, you may consider upgrading to latest version or at least 4.27

Printed out Kwargs[‘commit_ids’]:

2024-09-12 10:59:46.127 [3047] INFO [rhodecode.extra_pre_commits] [{u’name’: u’master’, u’ref’: u’refs/heads/master’, u’new_rev’: u’753f7f9bf485c5aafbbd612dc64ecec20530dc43’, u’old_rev’: u’c67ce784f659572d9fc91579d19a33f78f8e830e’, u’type’: u’heads’}]

Error logs:

2024-09-12 10:59:46.127 [3047] ERROR [rhodecode.lib.hooks_daemon] Exception when handling hook <function pre_push at 0x7f8e8eb19230>
Traceback (most recent call last):
File “/opt/rhodecode/store/p9vr3b65srfrkr4gbag23mpcdkk0xy6w-python2.7-rhodecode-enterprise-ce-4.12.4/lib/python2.7/site-packages/rhodecode/lib/hooks_daemon.py”, line 288, in _call_hook
result = hook(extras)
File “/opt/rhodecode/store/p9vr3b65srfrkr4gbag23mpcdkk0xy6w-python2.7-rhodecode-enterprise-ce-4.12.4/lib/python2.7/site-packages/rhodecode/lib/hooks_base.py”, line 115, in pre_push
pre_push_extension(repo_store_path=Repository.base_path(), **extras)
File “/opt/rhodecode/store/p9vr3b65srfrkr4gbag23mpcdkk0xy6w-python2.7-rhodecode-enterprise-ce-4.12.4/lib/python2.7/site-packages/rhodecode/lib/hooks_base.py”, line 291, in call
return callback(**kwargs_to_pass)
File “/home/rhodecode/.rccontrol/community-1/rcextensions/init.py”, line 183, in wrapper
return func(*args, **kwargs)
File “/home/rhodecode/.rccontrol/community-1/rcextensions/init.py”, line 165, in wrapper
return func(*args, **kwargs)
File “/home/rhodecode/.rccontrol/community-1/rcextensions/init.py”, line 450, in _pre_push_hook
commit_list = extra_pre_commits.run(*args, **kwargs)
File “/home/rhodecode/.rccontrol/community-1/rcextensions/extra_pre_commits.py”, line 164, in run
new_environ = dict((k, v) for k, v in rev_data[‘git_env’])
KeyError: ‘git_env’

Yep seems that version upgrade should resolve this, to clarify, we have 2 documentations, one is for legacy 4.x versions,
https://docs.rhodecode.com/4.x/rce/index.html
another for actual 5.x version - make sure you refer to correct documentation.
https://docs.rhodecode.com/5.x/rce/index.html

Also, update at least to 4.27 should resolve this, as your version is from 2018 and lots of improvements was done since then

Hope this helps!

Hi @tseast ,

Please, let me know if you were able to solve the problem or need another assistance.

Regards, Artem

Hello,

Thank you for reaching out! This effort/upgrade is currently paused. We are determining the priority within our company and will reach out if issues arise in the future.

Best,
TSEAST

Let us know if any other help required. If you stuck, we can allocate somebody to hop on the call with you and debug online.