05-03-2023 05:26 AM
I'd like to add a Git pre-commit hook to the Databricks Cluster.
This pre-commit hook should be executed when pushing to GitHub.
Why would I need a pre-commit hook on a Databricks Cluster?
My goal is to run blackbricks and format all notebooks automatically, so that well formatted code is pushed to GutHub only.
Is it possible to add a pre-commit hook to a Databricks Cluster?
I've found /root/.gitconfig on my cluster with this content:
[credential]
helper = cache
git config --global --list says:
credential.helper=cache
So, this seems to be the right (starting) place.
I've tried this:
git config -f /root/.gitconfig core.hooksPath /root/git-hooks
git config --global --list says now:
credential.helper=cache
core.hookspath=/root/git-hooks
Then I've added a pre-commit hook to the directory /root/git-hooks
The content of the pre-commit hook is:
touch /root/git-hooks/test.sample
This works, if I run it manually. The file test.sample is created in /root/git-hooks/.
File test.sample deleted.
In Databricks UI:
The file test.sample in /root/git-hooks/ has not been created -> The pre-commit hook was not executed.
What can I do to add a pre-commit hook to a Databricks Cluster, so that this pre-commit hook is executed before the commit (to the remote branch) is added?
05-03-2023 06:03 AM
Very interesting question!
Git on Databricks is not bound to a cluster, the code is separated from the clusters. So to use git pre-commit hooks, we need a way to configure git on Databricks (aka Repos). The only place where you can do this is in the admin panel. I looked and there is no possibility to add pre-commit hooks.
But this is definitely an interesting feature to have.
Maybe someone pulled it off in some way? If not:
you should post it as a feature request IMO.
05-03-2023 06:03 AM
Very interesting question!
Git on Databricks is not bound to a cluster, the code is separated from the clusters. So to use git pre-commit hooks, we need a way to configure git on Databricks (aka Repos). The only place where you can do this is in the admin panel. I looked and there is no possibility to add pre-commit hooks.
But this is definitely an interesting feature to have.
Maybe someone pulled it off in some way? If not:
you should post it as a feature request IMO.
05-05-2023 07:00 AM
Thanks a lot for your answer.
I'll create a FR
There is an existing FR already
05-19-2023 12:45 AM
Hi @Dejan Hrubenja
Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help.
We'd love to hear from you.
Thanks!
05-19-2023 01:35 AM
There is no possibility to add/use pre-commit hooks with Databricks yet.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group