Skip to content

Instantly share code, notes, and snippets.

@FinchPowers
Created December 1, 2022 15:22
Show Gist options
  • Save FinchPowers/1f72ca95698e2a77dcd28ed9605aa76f to your computer and use it in GitHub Desktop.
Save FinchPowers/1f72ca95698e2a77dcd28ed9605aa76f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Drop this in a project .git/hooks/prepare-commit-msg
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
# SHA1 is not empty if it's a rebase / ammend
SHA1=$3
# template
# summary
# <blank line>
# ref: <extracted ticket id>
# rest of default commit message
if [ -z "$COMMIT_SOURCE" ] && [ -z "$SHA1" ]; then
MSG="
ref: $(git branch --show-current | grep -E --only-matching '^LL22-[0-9]+')
"
fi
MSG="$MSG$(cat $COMMIT_MSG_FILE)"
printf "$MSG" > $COMMIT_MSG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment