Commit Messsage validation

Hi All,

With pre repositiory hook of stash plugin I able to achieve the commit message validation.

In commit messaage I want to include the ticket number like this "PROJ#123"

$git commit -m "123" text.txt (Incorrect)

$git commit -m "123" text.txt (Incorrect)

$git commit -m "PROJ#123" text.txt (Correct)

$git push origin "branch-name"

But by the time I hit above git push then incorrect commit messages also pushed to stash server.

How to restrict this. If I need to push the valid commits to stash server.

Regards

Anil

4 answers

Commit Policy Plugin does exactly what you requested.

Before version 2.0.0, it executed the verifications only when users pushed their changes to the central repo. Version 2.0.0 introduced the concept of local verifications (based on the pre-commit hook type of Git), so commits can also be verified in the developer's clone repo!! Of course, the two can (and should) be combined for the best results.

See: http://www.midori-global.com/products/jira-commit-policy-plugin/documentation/git#installing-local-commit-hooks

(It works with or without Bitbucket Server, but if that's your primary tool, also check out Commit Policy Plugin for Bitbucket Server, which is a lightweight connector from Bitbucket Server to JIRA.)

 

Hi,

You can only accept or reject the entire push with all the commits in it. The best you can do to prevent this from causing problems is to instruct your users to push commits one by one.

If you have them working in feature branches (highly recommended), this will not cause a problem.

Hi Balazs,

How can I restrict the locally saved means not valid commets(my validation failed) ones shouldn't be pushed to serveer with proper commits.

As per my validation proper commit messages only need to push to the server.

Thanks in advance

Anil

You can write a client-side commit hook to check the individual commits as soon as they are created, before they are pushed.

Hi Balazs,

I have gone through that. But My doubt here is.

Stash Admin will create a project,repository. The normal developer(s) will clone it in his individiual machine. Now Once clone complete developers will get the .git & inside hooks folder etc.,

As u suggested this client side commit hook should be done by developer. But for suppose 10 developers cloned that project ..they have to do commit validations client side?.. It shouldn't be..For restricting the admin should apply a hook for valid commiting.

I'm check I think developer shouldn't do pre client side commit hook. Before cloning the project if the admin apply the hook then that should apply in .git->hook folder.

I'm trying to achieve it with your suggestion, .

Thanks

Anil

We only have a server-side pre-receive hook and all developers are told that their entire push will be rejected if even only one of the commits fails the check. Since we work in feature branches (ie. the devs do not interfere with each others' work if they push often), we recommend that they push every commit immediately to Stash. This way, if the push gets rejected, they can amend the one commit and try again.

This method seems to work very nicely, no need for any client-side magic.

So,

For each commit we need to push to the server. For now no alternate? other than this..?

Il skip for client side commit hook. Il try to suggest our developers for each commit and pushing to server.

Thanks for this tip Il get back.

Regards

Anil

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

406 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you