Skip to content

Instantly share code, notes, and snippets.

@eliaskanelis
Created November 4, 2024 03:19
Show Gist options
  • Save eliaskanelis/6a009d11e6ee1d67fb8b02d424b0741e to your computer and use it in GitHub Desktop.
Save eliaskanelis/6a009d11e6ee1d67fb8b02d424b0741e to your computer and use it in GitHub Desktop.
#!/bin/sh
# Script to append a prefix to the commit message
commitMsgIn="$1"
commitType="$2"
branchName="$(git rev-parse --abbrev-ref HEAD)"
echo "Commit msg in = '$( cat "${commitMsgIn}")'"
echo "Commit type = '${commitType}'"
if [ "${branchName}" = "HEAD" ]; then
echo "You are in a detached HEAD state. Can not commit."
return 1
fi
# Define the prefix
prefix=$(echo "${branchName}" | sed -n 's/.*\/\([A-Z][A-Z]*-[0-9]*\).*/\1/p')
if [ -n "${prefix}" ]; then
prefix="${prefix} "
fi
# Append the prefix to the commit message
commitMsg="${prefix}$(cat "${commitMsgIn}")"
# Display the ne commit message
echo "Commit msg out = '${commitMsg}'"
# Check if the commit message is being created (not for merges)
if [ "${commitType}" != "merge" ]; then
# Write commit message
echo "${commitMsg}" > "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment