Skip to content

Instantly share code, notes, and snippets.

@tomaszprasolek
Created July 9, 2020 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaszprasolek/ec09495129547979e1edd17738a6517f to your computer and use it in GitHub Desktop.
Save tomaszprasolek/ec09495129547979e1edd17738a6517f to your computer and use it in GitHub Desktop.
V2 version - withoun # before task number
#!/bin/sh
BRANCH_NAME=$(git symbolic-ref --short HEAD)
STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/.*-\([0-9]\)/\1/p') # Get story number from branch name - "my_feature_branch-123"
COMMIT_MSG=`cat $1`
if [ x != x${STORY_NUMBER} ]; then # Checf if STORY_NUMBER is NOT empty
if [ x = x${2} ]; then # Check if commit message is empty
sed -i.back "1s/^/$STORY_NUMBER/" "$1"
elif [[ $COMMIT_MSG != *$STORY_NUMBER* ]]; then # # Commit message is not empty and NOT contains story number [git commit --amend --no-edit]
sed -i.back '${s/$/'" $STORY_NUMBER"'/}' "$1" # Add story number at the end of line
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment