Skip to content

Instantly share code, notes, and snippets.

View jlurena's full-sized avatar

Jean Luis Urena jlurena

View GitHub Profile
@jlurena
jlurena / git-commit-message.sh
Created December 8, 2020 17:02
Prepend JIRA Card number in Git commit message
#!/bin/bash
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
PREFIX_PATTERN='[A-Za-z]{2,10}(-|_)[0-9]{1,6}'
# Ensure BRANCH_NAME is not empty and is not in a detached HEAD state (i.e. rebase).
# SKIP_PREPARE_COMMIT_MSG may be used as an escape hatch to disable this hook,
# while still allowing other githooks to run.
if [ ! -z "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "HEAD" ] && [ "$SKIP_PREPARE_COMMIT_MSG" != 1 ] && [[ $BRANCH_NAME =~ $PREFIX_PATTERN ]]; then