Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×This seems to be intentional. As a result, my developers need to include the issue key in each commit to a feature/hotfix/bugfix branch, and then I must add it AGAIN when I merge their branch into a development trunk.
I've got that "I'm doing it wrong" feeling, but I've found quite a few posts on these forums with the same problem, and this seems like an obvious inefficiency.
Stash is creating my branches, from Jira, and naming them per Stash's naming conventions. I'm surprised that Bamboo cannot map the builds back to the JIRA issues that it addresses, without explicitly noting them in commit messages.
HALP, what am I missing?
EDIT: according to this: https://confluence.atlassian.com/display/BAMBOO057/Using+plan+branches#Usingplanbranches-configurebranch the commit message should not be necessary, at least for the linking of plan branches back to JIRA issues.
the "prepare-commit-msg" hook needs to be in each developer clone, not on the server.
#!/bin/sh # # check if commit is merge commit if [ "$2" == "merge" ]; then exit fi ISSUE_KEY=$(git symbolic-ref --short HEAD | sed -n -E 's/.*[/]([A-Z]{2,10}-[0-9]{2,10}).*/\1/p') if [ "$ISSUE_KEY" == "" ]; then # no issue key in branch, use the default message exit fi TPL=$(cat $1) SUBJECT=$(head -n 1 $1) if echo "$SUBJECT" | grep -q "\b$ISSUE_KEY\b" ; then # issue key already present in the message exit fi case $2 in message) echo -n "$ISSUE_KEY " >$1 ;; template) ;; squash) ;; merge) ;; *) echo "#$ISSUE_KEY " >$1 ;; esac echo "$TPL">>$1 exit
This also works with tools like SourceTree. Notice the extra # in case a commit editor is used, The user is supposed to remove the hashtag and add more text. We do this to disallow developers to just hit save.
Much appreciated Mike! Would you be able to provide some high level on setup/usage?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just copy that file as prepare-commit-msg into .git/hooks. No special usage instruction, everything should work the same. The issue id will appear in commit message subjects if they are in branchnames (in the syntax as created by JIRA)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For SourceTree you write the commit message and the issue id will appear afterwards, after committing. For the git command line when using a commit editor, you will see the issue id in the editor.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is very helpful...thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm...for some reason it's not working for me. 1. I've tried running both with git commit and git commit -m 'test commit' 2. My branchname is in the format "release-PROJECTNAME-1-test-commit" What could I be missing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Justin - how did you get it to work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had done that too. Could my script be wrong? What did Mike mean by "Notice the extra # in case a commit editor is used..." ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
He just means that the issue key is prefixed with # in the commit message.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I edited my question to ask how this fits in:
Sounds like we shouldn't need to include any comments to have plan branches linked back to JIRA issues. The default branch naming convention appears to satisfy the "Integrating branches with JIRA" section.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Mike. Are you using a traditional git hook in each repository, or did you configure a hook in Stash? I don't see any obvious plugins/hooks in the marketplace for the later, so I guess I'll come up with a regex and some bash to implement the former.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Having the JIRA issue-id in the commit message is the right thing to do.
In git it is normal in several branching models (e.g. gitflow) to delete branches once they are merged. Only the commits themself are persistent. You only need to "copy" the ids into the merge commit if you use a squash merge strategy. But then you need to copy heach commits headline anyway.
We use a commit message hook to auto-prepend commit messages with the issue-id from the branch name. With that developers only need to create branches inside JIRA and dont need to type the issue IDs anywhere.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mike, this sounds immensely helpful. What did you get this "hook", or was it custom created?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.