Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can I run and check the output of a git hook in a merge check script?

Ionut Eduard Oprescu April 28, 2021

Hello,

 

I am trying to set up a merge check script that will reuse an existing pre-commit git hook in my repository(from the ".git/hooks" folder) and if the hook returns the ok status I will allow the merge.

From my understanding the ".git/hooks" folder is only local so I will upload the hook somewhere in the repo if that is needed.

 

My main goal is to check if that hook returns OK when someone is trying to merge into the main branch because that will be easier for newcomers that do not have the hook setup locally.

Also some way of checking the hook on the server side when they are pushing would help.

 

Is there any way to achieve this behavior using Scriptrunner or maybe other basic git functionalities?

Thank you!

1 answer

1 accepted

0 votes
Answer accepted
Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2021

Hi @Ionut Eduard Oprescu ,

Firstly I'd like to clarify if you are using Bitbucket Cloud or Bitbucket Server/DC?

I ask, because the tags for this Community question are for both Bitbucket Cloud and ScriptRunner. However ScriptRunner is currently only compatible with Bitbucket Server/DC.

If you are using Bitbucket Server/DC, then the ScriptRunner for Bitbucket team would first recommend you try and rewrite your local pre-hook as either a server-side custom pre-hook or merge-check using ScriptRunner.

The documentation for a custom pre-hook can be found here: https://docs.adaptavist.com/sr4bib/6.25.0/features/script-pre-receive-hooks/custom-pre-receive-hooks

And the documentation for a custom merge-check can be found here: https://docs.adaptavist.com/sr4bib/6.24.0/features/script-merge-checks/custom-merge-check

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Ionut Eduard Oprescu May 12, 2021

Hello,

I do have ScriptRunner in my repository settings so using the pre-hook or merge-check is the way to go, but at the same time I am looking for a way to reuse my existing local hooks in those scripts.

Maybe that could be a good addition to ScriptRunner functionalities.

Thank you for your answer!

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 13, 2021

@Ionut Eduard Oprescu ,

Thank you for your answer.

I'm guessing that currently the issue is that your local hooks are written in a language other than Groovy? And hence require re-writing for ScriptRunner.

It is something we will consider. But for now is not something we currently support.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Ionut Eduard Oprescu May 14, 2021

That is the case, my scripts are in bash/sh.

I marked the question as answered since I got the info I needed.

Thank you for your replies!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events