Last active
March 16, 2022 16:11
-
-
Save nok/959e0d060893961675b5924948edb52b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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