Skip to content

Instantly share code, notes, and snippets.

@nok
Last active March 16, 2022 16:11
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 nok/959e0d060893961675b5924948edb52b to your computer and use it in GitHub Desktop.
Save nok/959e0d060893961675b5924948edb52b to your computer and use it in GitHub Desktop.
mkdir -p ~/.git-templates/hooks
rm -f ~/.git-templates/hooks/prepare-commit-msg
cat <<EOT >> ~/.git-templates/hooks/prepare-commit-msg
#!/bin/bash
FILE=\$1
MESSAGE=\$(cat \$FILE)
BRANCH=\$(git branch | grep '*' | sed 's/* //')
TICKET=\$(echo \$BRANCH | grep -Eo '^(DALI-)[0-9]+')
if [[ \$TICKET ]];then
echo "\$MESSAGE (\$TICKET)" > \$FILE
elif [[ ! -z "\$BRANCH" ]];then
BRANCH=\$(echo "\$BRANCH" | sed 's/\(.\{15\}\).*/\1.../')
echo "\$MESSAGE (\$BRANCH)" > \$FILE
fi
EOT
chmod a+x ~/.git-templates/hooks/prepare-commit-msg
git config --global init.templatedir '~/.git-templates'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment