Last active
January 24, 2021 10:02
-
-
Save harrytran998/5fb1419525827601f2e7515505164d10 to your computer and use it in GitHub Desktop.
Githooks
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
Z |
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
A |
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
Tạo 1 file là `prepare-commit-msg` ở githooks với nội dung sau | |
```bash | |
#!/bin/bash -e | |
textBase='\033[0m' | |
textInformation='\033[1;34m' | |
textSuccess='\033[1;32m' | |
branchName=$(git rev-parse --abbrev-ref HEAD) | |
entradeTicketRegex='^ENTRADE-[0-9]+|merge|hotfix' | |
gitCommitMsg=$(head -n 1 "$1") # $1 is path = .git/COMMIT_EDITMSG | |
if [[ $gitCommitMsg =~ $entradeTicketRegex ]];then | |
echo -e "$textInformation Already exist prefix branch-name, ignore appending prefix." | |
echo -e "$textBase" | |
else | |
echo -e "$textInformation Starting append prefix branch-name..." | |
if [[ -n "$branchName" ]] && [[ $branchName =~ $entradeTicketRegex ]]; then | |
# Append prefix branch name into commit message | |
sed -i.bak -e "1s~^~$branchName ~" "$1" | |
echo -e "$textSuccess Append prefix branch-name successfully." | |
echo -e "$textBase" | |
fi | |
fi | |
``` | |
--> Run `make git-hook` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment