Difference between revisions of "Git & Atlassian"

From Briki
Jump to: navigation, search
(Hook to add branch/issue name to feature branches)
Line 15: Line 15:
  
 
=== Hook to add branch/issue name to feature branches ===
 
=== Hook to add branch/issue name to feature branches ===
This enables JIRA/Bamboo integration so that JIRA can detect build status in the Development pane
+
This enables JIRA/Bamboo integration so that JIRA can detect build status in the Development pane. Add to .git/hooks/prepare-commit-msg (also works on Windows, at least with msysgit).
 
<pre>
 
<pre>
 
#!/bin/sh
 
#!/bin/sh

Revision as of 14:58, 5 December 2014

Simple workflow

  • Create JIRA issue
  • Click "Create Branch" on JIRA issue (check source branch)
    • This will transition the JIRA issue to In Progress
  • git fetch
  • git checkout branchname (this will automatically create the new branch locally, based on the new remote branch)
  • Make changes
  • git commit -am "My commit description"
  • git push
  • Create pull request
    • This will transition the JIRA issue to In Review
  • Merge on build success, and optionally delete branch
    • This will transition the JIRA issue to Done
  • Delete branch locally if desired, with git branch -d branchname

Hook to add branch/issue name to feature branches

This enables JIRA/Bamboo integration so that JIRA can detect build status in the Development pane. Add to .git/hooks/prepare-commit-msg (also works on Windows, at least with msysgit).

#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
# Modified from the stackoverflow answer here: http://stackoverflow.com/a/11524807/151445
#
 
# Succeed on all merge messages, as evidenced by MERGE_MSG existing
[ -f $GIT_DIR/MERGE_MSG ] && exit 0
 
# Get branch name and description
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
 
case "$NAME" in
  feature/*)
	# Append branch name and optional description to COMMIT_MSG
	# For info on parameters to githooks, run: man githooks
	ISSUE=$(echo $NAME | sed 's/feature\/\([A-Z]*-[0-9]*\).*/\1/')
	if [ "$ISSUE" != "$NAME" ]; then
	  echo -e "\nIssue: $ISSUE" >> "$1"
	  BRANCH_PREFIX=""
	else
	  BRANCH_PREFIX="\n"
	fi
	echo -e "${BRANCH_PREFIX}Branch: $NAME $DESCRIPTION" >> "$1"
esac