It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Commit Messsage validation

anil kumar Mar 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

4 answers

1 vote
Ferenc Kiss [Midori] May 04, 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
Balazs Szakmary Mar 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 Mar 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

0 votes
Balazs Szakmary Mar 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 Mar 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
Balazs Szakmary Mar 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 Mar 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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,925 views 1 19
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you