Last active
August 30, 2024 07:22
-
-
Save lengocthuong15/bf1796ccc1d5fbde10fdf721bab1ebf1 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
#!/bin/sh | |
# | |
# Git commit-msg hook. If your branch name is in the form "LMS-1234-postfix", or | |
# "LMS-1234_postfix", it automatically adds the prefix "[LMS-1234]: " to commit | |
# messages. | |
# Example | |
# ======= | |
# | |
# git checkout -b LMS-1234-some-cool-feature | |
# git commit "new stuff" | |
# git log => will show up "[LMS-1234]: new stuff" | |
#If you include "#noref" in the commit message, nothing will be added to the | |
# commit message, and the "#noref" itself will be stripped. | |
# | |
# Example | |
# ======= | |
# | |
# git commit "don't prefix this message #noref" | |
# git log => will show up "don't prefix this message" | |
# | |
# Install | |
# ======= | |
# | |
# cd your_project | |
# curl https://gist.githubusercontent.com/lengocthuong15/bf1796ccc1d5fbde10fdf721bab1ebf1/raw > .git/hooks/commit-msg | |
# chmod +x .git/hooks/commit-msg | |
# | |
TICKET=$( git symbolic-ref HEAD | grep -o -E "[A-Z]+-[0-9]+") | |
COMMIT_FILE=$1 | |
COMMIT_MSG=$(cat $1) | |
NO_REF=$(echo $COMMIT_MSG | grep -oP "#noref") | |
echo $NO_REF | |
if [ -z "$TICKET" ] #If ticket id is empty, just commit as normal | |
then | |
if [ -z "$NO_REF" ] | |
then | |
echo "$COMMIT_MSG" > $COMMIT_FILE | |
else | |
echo "$COMMIT_MSG" | sed 's/#noref//g' > $COMMIT_FILE | |
fi | |
else | |
if [ -z "$NO_REF" ] | |
then | |
echo "[$TICKET]: $COMMIT_MSG" > $COMMIT_FILE | |
else | |
echo "$COMMIT_MSG" | sed 's/#noref//g' > $COMMIT_FILE | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment