Created
January 6, 2023 15:57
-
-
Save naclsn/f1343d8ff09dbebe036e20c129c05ed9 to your computer and use it in GitHub Desktop.
Add branch name to commit message.
This file contains hidden or 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
#!/bin/sh | |
# prepend branch name to message | |
# aborts on empty message | |
# not applied for branch `main` | |
# by-passe by prefixing with '!!' | |
# (in which these are removed) | |
two=`head -c 2 "$1"` | |
case ${two:-#} in | |
\#*) : >"$1"; exit 1;; | |
\!!) sed -i 1s/^..// "$1"; exit 0;; | |
esac | |
branch=`git rev-parse --abbrev-ref HEAD` | |
[ main = $branch ] || sed -i 1s/^/$branch:\ / "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment