Last active
October 1, 2019 19:17
-
-
Save arempe93/749225f9d28d21d8d9154f6166b8e38d to your computer and use it in GitHub Desktop.
Automatic commit msg prefix for Clubhouse
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/bash | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
BRANCH_ADDED=$(grep -c "\[$BRANCH_NAME\]" $1) | |
## if branch was not manually added and BRANCH_NAME is not empty + starts with "ch" | |
if ! [[ $BRANCH_ADDED -ge 1 ]] && [ -n $BRANCH_NAME ] && [[ $BRANCH_NAME =~ ^ch.* ]]; then | |
# remove everything after - or / (ch122/my-branch => ch122) | |
BRANCH_NAME="${BRANCH_NAME%%[-/]*}" | |
sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install:
./.git/hooks/prepare-commit-msg.sample
in editormv ./.git/hooks/prepare-commit-msg.sample ./.git/hooks/prepare-commit-msg
chmod +x ./.git/hooks/prepare-commit-msg