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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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

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

0 votes

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Bitbucket

Contest: Share your custom Bitbucket Pipe and win

Announced in this blog, this holiday season we’re celebrating all things CI/CD and between now and the end of 2019 we’ll be showcasing content, use cases, feature announcements and more. One featur...

2,126 views 11 6
Join discussion

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