Created
May 10, 2023 09:33
-
-
Save vitormil/a5e819fce89e455059eba00da3ede999 to your computer and use it in GitHub Desktop.
Git Hooks
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 | |
current_branch=`git rev-parse --abbrev-ref HEAD` | |
if [[ $current_branch =~ master|main ]]; then | |
message="Please don't commit directly to $current_branch." | |
echo "💥 \033[1;31mERROR: $message\033[0m"; | |
exit 1 | |
fi |
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 | |
[ -f $GIT_DIR/MERGE_MSG ] && exit 0 | |
COMMIT_MSG_FILE=$1 | |
COMMIT_SOURCE=$2 | |
SHA1=$3 | |
quote1=$(ruby ~/vitor/quotes/quote.rb) | |
quote2=$(ruby ~/vitor/quotes/quote.rb --color) | |
# Only add custom message when there is no commit source | |
if [[ -z "$COMMIT_SOURCE" ]] | |
then | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
if [[ $CURRENT_BRANCH =~ ^(.+\/)?([A-Z]+-[0-9]*).* ]] | |
then | |
JIRA_ID="${BASH_REMATCH[2]}" | |
hint=$(cat "$COMMIT_MSG_FILE") | |
echo "[${JIRA_ID}] " > "$COMMIT_MSG_FILE" | |
echo "$hint" >> "$COMMIT_MSG_FILE" | |
echo "# Quote of the commit:\n#\t${quote1}" >> "$COMMIT_MSG_FILE" | |
echo "#\n#\n# Quote of the commit:\n#\n# ${quote2}\n#\n#\n" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment