Skip to content

Instantly share code, notes, and snippets.

@minamaged113
Created February 11, 2021 20:23
Show Gist options
  • Save minamaged113/31e8dff7f66785f8d4ee36c587aae8d1 to your computer and use it in GitHub Desktop.
Save minamaged113/31e8dff7f66785f8d4ee36c587aae8d1 to your computer and use it in GitHub Desktop.
git hook to edit commit message
#!/bin/bash
# git hook to add ticket number from branch name
# branch names should have the following naming
# convention for this to work:
# <type>/<ticket-handle-without-hashes>-<ticket-title>
BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)"
COMMIT_MSG=$(cat "$1")
TICKET_NO_FROM_BRANCH_NAME=$(echo $BRANCH_NAME | cut -d "/" -f 2 | cut -d "-" -f 1)
grep -qs "^$TICKET_NO_FROM_BRANCH_NAME" "$1" || echo "[$TICKET_NO_FROM_BRANCH_NAME] $(cat "$1")" > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment