Commit Messsage validation

anil kumar March 25, 2014

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

6 answers

1 vote
Midori
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2016

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.)

 

0 votes
raghuveer bapuram December 8, 2020

to apply hook on Bit Bucket to validate all the check-in for Jira/ QC/ CR number before they are checked in.

The check-in without this details in comments should not be allowed.

0 votes
raghuveer bapuram December 8, 2020

could you kindly help how to apply 

to apply hook on Bit Bucket to validate all the check-in for Jira/ QC/ CR number before they are checked in.

The check-in without this details in comments should not be allowed.

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

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.

anil kumar March 30, 2014

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

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

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

anil kumar March 30, 2014

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

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2014

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.

anil kumar March 27, 2014

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events